Decoding gcc compile options

GCC/G++ has wide variety of options.

Most used options.

-c    // just complie to .o file
-o    // name of the executable
-Wall // display all warnings
-lm   // link math lib

More advanced options

-shared -o libfoo.so 
-lfoo
-I     // Checks for dir of the include headers in addtion to default
-L     // checks for lib dir for libraries (in addtion to default) at link time
-rpath // checks for lib dir for libraries (in addtion to default) at run  time
readelf -d libfoobar.so
 0x0000000000000001 (NEEDED)             Shared library: [libfoo.so]
 0x0000000000000001 (NEEDED)             Shared library: [libbar.so]

readelf -d prog 
 0x0000000000000001 (NEEDED)             Shared library: [libfoobar.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000001d (RUNPATH)            Library runpath: [.]

strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
..
GLIBCXX_3.4.29
GLIBCXX_DEBUG_MESSAGE_LENGTH


★ 2 min read · Rajesh Pandian M · gcc