Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force to link against unused shared library

Tags:

c++

linux

gcc

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?

like image 588
queen3 Avatar asked Jul 24 '12 12:07

queen3


People also ask

Are shared libraries linked?

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.

Which option of gcc compiler provides the linking with shared libraries?

6. Which option of GCC compiler provides the linking with shared libraries? Explanation: None.

What is a linker flag?

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.


1 Answers

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

like image 113
Jonathon Reinhart Avatar answered Oct 06 '22 10:10

Jonathon Reinhart