The main differences:
gcc will compile: .c/.cpp files as C and C++ respectively.
g++ will compile: .c/.cpp files but they will all be treated as C++ files.
Also if you use g++ to link the object files it automatically links in the std C++ libraries (gcc does not do this).
$ clang++-6.0 main.cpp
Searching through clang documentation
clang --help | grep "\-I "
$ clang --help | grep "\-o "
-o <file> Write output to <file>
Only run preprocess, compile, and assemble steps no linking generates a target “.o” object file.
-std=<standard>
sets standard library. This must be set if you are to use new features of c++. Use -std=c++2a for c++20
The default name of the output file is a.out but this can be changed
-D<macroname>=<value>
If we have the following file: main.cpp
We can choose which code to run using -D
or this without a space
or running this:
-I<dir>, --include-directory <arg>, --include-directory=<arg>
If we had these 3 files but MyClass.cpp and MyClass.hpp were in a different folder
include/MyClass.hpp
src/MyClass.cpp
src/main.cpp
To compile we would have to do something like this:
This will look for our headers in the include directory. This allows us to organize our files.
A few more important flags
g++/gcc specific flag
In order to compile with all warnings enabled and to produce standards-compatible C++ code, I recommend using the flags
more info clang more info 2nd link