Creating and using shared library
gcc -shared -fPIC foo.c -o foo.so export LD_PRELOAD=`pwd`/foo.so
If using relative path to specify shared library,
ld.sowill report error for can’t preload the specified library and ignore that error.
On Mac OS X:
gcc -dynamiclib -undefined suppress -flat_namespace foo.c -o foo.dylib export DYLD_INSERT_LIBRARIES=`pwd`/foo.dylib
Also not the
DYLD_LIBRARY_PATHenvironment variable. From Where is LD_PRELOAD under Mac OS X?
dyld will look for the library in the specified location. If it does not exist, it will look in specific library paths specified in DYLD_LIBRARY_PATH. If the linking works and the library is able to match the symbols, the program will run, otherwise it will fail.
For more information about dynamic library on OS X, refer to my Mac notes.
List all pre-defined macros
From Stack Overflow, Using the following command
touch dummy cpp -dM ./dummy
-fmudflapfind pointer arithmetic errors during runtime
-fstack-checkstack overflow protection
-gnatochecks for overflows during integer operations
Extensions to C