1

I am new to C++ and suppose I have three files main.cpp, test.cpp and test.h. The main.cpp file includes the test.h header file.

Now to successfully compile the files I am using the following command:

g++ main.cpp test.cpp -o main.exe

Is there a way to only supply main.cpp and the compiler would automatically compile all the required files?

Thank you.

Prabodh
  • 165
  • 2
  • 12
  • 1
    You could look at building a `Makefile`. – Galik May 16 '21 at 04:16
  • You want a build system. My personal favorite is DDS, but it's still in its infancy (not yet 1.0). Popular cross-platform ones are: CMake, Meson, Build2, Bazel. Makefiles are one of the most common, but they are trickier to set up correctly and harder to make cross-platform to non-Unix systems (e.g. Windows). – Justin May 16 '21 at 04:40
  • I wish there was something as simple, Bazel (https://bazel.build/) and Evoke (https://github.com/dascandy/evoke, https://www.youtube.com/watch?v=mWOmkwv8N_U) promise that, but I never had the opportunity to try them. – alfC May 16 '21 at 04:58
  • https://stackoverflow.com/questions/67372416/how-would-i-compile-multiple-files-in-a-folder/67372615#67372615 Check this answer – ThivinAnandh May 16 '21 at 05:26

1 Answers1

0

if you are using vs code u can download c/c++ extension by microsoft then u hit f6 it will compile all .cpp file on your directory and add f3 to help this will add super powers and allow it to fly. bc red bull gives u wings

Community
  • 1
  • 1