1

I wrote a small driver program utilizing static version of GNU gmp library. I observed that the library itself is 1.2 MB while the driver executable is of 237 KB. This has led me to believe that the linker ld is smart enough to include only the required code from the library, thus eliminating the unnecessary instructions to prevent the executable from being bulky.

Is there any means to instruct ld to link the entire gmp library (even the unnecessary code) starting at some specified location?

1
  • If I specify .a archive, then only it occurs. – Holmes.Sherlock Oct 26 '15 at 8:25
0

Calling ld with the --whole-archive option forces it to load all library objects rather than just the ones that are used in your source file. If you don't want to apply this to all libraries, use the --no-whole-archive option before any libraries that you want the standard linking behavior to apply to.

Use of these options is detailed in the man page for ld.

Not the answer you're looking for? Browse other questions tagged or ask your own question.