title: VS Code build c++ programs with multiple .ccp source files
body: <p>I've installed Microsoft VSCode under Linux Mint, and opened a folder named <strong>test1</strong> containing 3 files:</p>
  <blockquote>
  <p><strong>test.cpp</strong> - pre-declares <strong>foo()</strong> and <strong>bar()</strong>, then calls both functions in <strong>main()</strong><br />
  <strong>foo.cpp</strong> - defines function <strong>foo()</strong><br />
  <strong>bar.cpp</strong> - defines function <strong>bar()</strong></p>
  </blockquote>
  <p>When I compile <strong>test.cpp</strong> (using <strong>F5 Start debugging</strong> in VSCode) it fails with <em>undefined reference to <strong>foo</strong>()</em> and <em>undefined reference to <strong>bar</strong>()</em>. When I compile <strong>foo.cpp</strong> and <strong>bar.cpp,</strong> they both fail with <em>undefined reference to <strong>main</strong>.</em></p>
  <p>I found <a href="https://stackoverflow.com/questions/47665886/vs-code-will-not-build-c-programs-with-multiple-ccp-source-files">VS Code will not build c++ programs with multiple .ccp source files</a> as asked here previously, from which I discover I can type the following in the VSCode &quot;Terminal&quot; window...</p>
  <blockquote>
  <p><strong>g++ test.cpp foo.cpp bar.cpp -o a.out</strong><br />
  <strong>./a.out</strong></p>
  </blockquote>
  <p>...and my program compiles and runs as expected (but I can't do any debugging, obviously).</p>
  <hr />
  <p>So what I want to know in the first instance is <em>How do I tell VSCode to compile and link in those two additional source files?</em></p>
  <p>Unless it's going to be blindingly difficult, I'd also like some guidance on how to go about moving on to Phase 2 of my task - compiling <strong>foo</strong> and <strong>bar</strong> into a &quot;library&quot; file that I can link across to when working on a project in folder <strong>test2</strong> (sibling to <strong>test1</strong>).</p>
  <p>If at all possible, I'd like to achieve this entirely within the context of the VSCode environment (maybe I'll think about learning the complexities of g++ and makefiles sometime in the future).</p>