How to use visual studio code to compile multi-cpp file?

For very simple projects you can simply pass multiple cpp files to the compiler in a single command, e.g:

g++ main.cpp a.cpp -o main.out

You can simply change your compile command in tasks.json to this value.

However as your project grows you will find this approach causes you more and more problems. I’d recommend you look into a proper build system, there are many to choose from including:

  • Make – the main standard build system on Linux but difficult to learn and fiddly
  • CMake – visual studio code has some support for cmake
  • Gyp – can generate make files
  • Scons – python like build scripts

Leave a Comment