title: How can I solve the error LNK2019: unresolved external symbol - function?
body: <p>I get this error, but I don't know how to fix it.</p>
  <p>I'm using Visual Studio 2013. I made the solution name <strong>MyProjectTest</strong>
  This is the structure of my test solution:</p>
  <p><img src="https://i.stack.imgur.com/uRUex.png" alt="The structure" /></p>
  <p>-<em>function.h</em></p>
  <pre><code>#ifndef MY_FUNCTION_H
  #define MY_FUNCTION_H
  
  int multiple(int x, int y);
  #endif
  </code></pre>
  <p><em>-function.cpp</em></p>
  <pre><code>#include &quot;function.h&quot;
  
  int multiple(int x, int y){
      return x*y;
  }
  </code></pre>
  <p>-<em>main.cpp</em></p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &quot;function.h&quot;
  
  using namespace std;
  
  int main(){
      int a, b;
      cin &gt;&gt; a &gt;&gt; b;
      cout &lt;&lt; multiple(a, b) &lt;&lt; endl;
  
      system(&quot;pause&quot;);
      return 0;
  }
  </code></pre>
  <p>I'm a beginner; this is a simple program and it runs without error.
  I read on the Internet and became interested in the unit test, so I created a test project:</p>
  <p>Menu <em>File</em> → <em>New</em> → <em>Project...</em> → <em>Installed</em> → <em>Templates</em> → <em>Visual C++</em> → <em>Test</em> → <em>Native Unit Test Project</em> →</p>
  <p>Name: <em>UnitTest1</em> <br/>
  Solution: <em>Add to solution</em></p>
  <p>Then the location auto-switched to the path of the current open solution.</p>
  <p>This is the folder structure of the solution:</p>
  <p><img src="https://i.stack.imgur.com/cvsCE.png" alt="Folder structure" /></p>
  <p>I only edited file <em>unittest1.cpp</em>:</p>
  <pre><code>#include &quot;stdafx.h&quot;
  #include &quot;CppUnitTest.h&quot;
  #include &quot;../MyProjectTest/function.h&quot;
  
  using namespace Microsoft::VisualStudio::CppUnitTestFramework;
  
  namespace UnitTest1
  {
      TEST_CLASS(UnitTest1)
      {
      public:
  
          TEST_METHOD(TestEqual)
          {
              Assert::AreEqual(multiple(2, 3), 6);
              // TODO: Your test code here
          }
  
      };
  }
  </code></pre>
  <p>But I get:</p>
  <blockquote>
  <p>error LNK2019: unresolved external symbol.</p>
  </blockquote>
  <p>I know that the implementation of function <em>multiple</em> is missing.
  I tried to delete the <em>function.cpp</em> file and I replaced the declaration with the definition, and it ran. But writing both declaration and definition in the same file is not recommended.</p>
  <p>How can I fix this error without doing that? Should I replace it with <code>#include &quot;../MyProjectTest/function.cpp&quot;</code> in file unittest.cpp?</p>