Compiling C/C++ code with GCC


The GNU Compiler Collection

They say that “On many systems, g++ is also installed with the name c++“.


Compile a C++ file into an object file:
[bash]
g++ -c main.cpp -o main.o
[/bash]

Link object file(s) into shared library:
[bash]
g++ -shared math.o -o libmath.so
[/bash]

Link object file(s) into static library:
[bash]
ar qcs libmath.a math.o
[/bash]

Link object files, static libraries and shared libraries into an executable binary:
[bash]
g++ -o main.bin main.o libmath.a libdef.so
[/bash]