How to remove unused C/C++ symbols with GCC and ld?

For GCC, this is accomplished in two stages: First compile the data but tell the compiler to separate the code into separate sections within the translation unit. This will be done for functions, classes, and external variables by using the following two compiler flags: -fdata-sections -ffunction-sections Link the translation units together using the linker optimization … Read more

How to print the ld(linker) search path

You can do this by executing the following command: ld –verbose | grep SEARCH_DIR | tr -s ‘ ;’ \\012 gcc passes a few extra -L paths to the linker, which you can list with the following command: gcc -print-search-dirs | sed ‘/^lib/b 1;d;:1;s,/[^/.][^/]*/\.\./,/,;t 1;s,:[^=]*=,:;,;s,;,; ,g’ | tr \; \\012 The answers suggesting to use … Read more

LD_LIBRARY_PATH vs LIBRARY_PATH

LIBRARY_PATH is used by gcc before compilation to search directories containing static and shared libraries that need to be linked to your program. LD_LIBRARY_PATH is used by your program to search directories containing shared libraries after it has been successfully compiled and linked. EDIT: As pointed below, your libraries can be static or shared. If … Read more

What’s the difference between .so, .la and .a library files?

.so files are dynamic libraries. The suffix stands for “shared object”, because all the applications that are linked with the library use the same file, rather than making a copy in the resulting executable. .a files are static libraries. The suffix stands for “archive”, because they’re actually just an archive (made with the ar command … Read more

I don’t understand -Wl,-rpath -Wl,

The -Wl,xxx option for gcc passes a comma-separated list of tokens as a space-separated list of arguments to the linker. So gcc -Wl,aaa,bbb,ccc eventually becomes a linker call ld aaa bbb ccc In your case, you want to say “ld -rpath .“, so you pass this to gcc as -Wl,-rpath,. Alternatively, you can specify repeat … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)