0

I am used to compiling a single main.cpp file with warnings using this command on terminal:

g++ -Wall -Wextra std=c++14 main.cpp -o main

Let's say I have 2 more files (file_1.cpp, file_2.cpp) that will link with main.cpp. I saw this command that compiles such files:

g++ -I path -c file_1.cpp -o file_1.o
g++ -I path -c file_2.cpp -o file_2.o

where path is the path directory of the header files. And then I compile the main.cpp and link it to the previous objects with:

g++ -I path -o main main.cpp file_1.o file_2.o

If I want to include the warnings -Wall -Wextra and standard -std=c++14, where do I write such options? On the final compilation of main.cpp, in each compilation of every file, somewhere else, or don't need to at all?

muon012
  • 57
  • 5
  • Is there a reason you want to compile from command line, instead of an IDE or makefile like system? – Richard Critten Nov 19 '19 at 18:53
  • @RichardCritten no reason, I am kind of new to programming and I was taught to use the command line instead of an IDE, so I am a bit used to this way. – muon012 Nov 19 '19 at 19:00

1 Answers1

0

You can use the flags in every compilation so you will get the warnings earlier. But I would prefer to create a makefile to automate the build process instead of typing everything. The following issue has good information about it -> How to make a SIMPLE C++ Makefile

Lautert
  • 376
  • 2
  • 5