title: How to import files in c++? and how to compile them successfully?
body: <p>I am trying to break my code into multiple files in c++. My main file is base.cpp in which I am trying to import foo.cpp. But it shows the following error during compilation. </p>
  
  <p><strong>Undefined symbols for architecture x86_64:
    "foo()", referenced from:
        _main in base-a3f2f3.o
  ld: symbol(s) not found for architecture x86_64</strong></p>
  
  <p>My base.cpp file is : </p>
  
  <pre><code>#include&lt;bits/stdc++.h&gt;
  #include "foo.h"
  using namespace std; 
  
  int main(){
      foo(); 
      cout&lt;&lt;tot&lt;&lt;endl;
      cout&lt;&lt;"bye"&lt;&lt;endl;
  }
  </code></pre>
  
  <p>My foo.cpp is : </p>
  
  <pre><code>#include&lt;bits/stdc++.h&gt;
  using namespace std ; 
  
  void foo(){
      cout&lt;&lt;"hello world"&lt;&lt;endl; 
  }
  int tot = 90;
  </code></pre>
  
  <p>My foo.h file is: </p>
  
  <pre><code>#ifndef FOO_H
  #define FOO_H
  int tot; 
  void foo(); 
  
  #endif 
  </code></pre>
  
  <p>I use the following command to compile my c++ files successfully : 
  g++ -std=c++14 filename.cpp &amp;&amp; ./a.out</p>
  
  <p>I use Mac. My code editor is VS Code.</p>
  
  <pre><code>My cpp configuaration is as follows : 
  {
  "configurations": [
          {
              "name": "Mac",
              "includePath": [
                  "${workspaceFolder}/**"
              ],
              "defines": [],
              "macFrameworkPath": [
                  "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
              ],
              "compilerPath": "/usr/bin/clang",
              "cStandard": "c11",
              "cppStandard": "c++17",
              "intelliSenseMode": "clang-x64"
          }
      ],
      "version": 4
  }
  </code></pre>
  
  <p>Thanks.</p>