Moved from gcc 4.5 to gcc 4.6, and now it does not link against libraries that are not used at compile time (i.e. if no symbols are imported from them).
However the purpose of those libraries is that they execute static constructors and thus make themselves available to the app at runtime (register their symbols).
Is there a way to force gcc to link with all libraries listed via -l?
Shared libraries (also called dynamic libraries) are linked into the program in two stages. First, during compile time, the linker verifies that all the symbols (again, functions, variables and the like) required by the program, are either linked into the program, or in one of its shared libraries.
6. Which option of GCC compiler provides the linking with shared libraries? Explanation: None.
The flag tells the linker to link in the produced binary only the libraries containing symbols actually used by the binary itself. This binary can be either a final executable or another library. In theory, when linking something, only the needed libraries are passed to the command line used to invoke the linker.
It looks like you need either -Wl,--no-as-needed
to totally disable it. Or, --no-as-needed -lfoo --as-needed
to disable "as-needed" just for libfoo
.
Source: https://lists.ubuntu.com/archives/ubuntu-devel/2010-November/031991.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With