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:
g++ -c main.cpp -o main.o

# Link object file(s) into shared library:
g++ -shared math.o -o

# Link object file(s) into static library:
ar qcs libmath.a math.o

# Link object files, static libraries and shared libraries into an executable binary:
g++ -o main.bin main.o libmath.a

# Link using -l instead of full path, and have some static libs and some dynamic libs:
gcc <objects> -o <binary> -Wl,-Bstatic <static_lib_list> -Wl,Bdynamic <dynamic_lib_list>


# Detect GLibC versions required by an executable file - The greatest version detected is required.
objdump -T bin/main.bin820 | grep GLIBC_ | awk '{print substr($0, index($0, "GLIBC_"))}' | awk '{print $1}' | sort -u
# Print include paths and linking paths:
g++ -E -x c++ - -v < /dev/null