How can I statically link only a some specific libraries to my binary when linking with GCC?
gcc ... -static ...
tries to statically link all the linked libraries, but I haven't got the static version of some of them (eg: libX11).
A static library is a programming concept in which shared libraries with special functionalities, classes or resources are linked to external applications or components, facilitating the creation of stand-alone and executable files.
The major disadvantages of static linking are increases in the memory required to run an executable, network bandwidth to transfer it, and disk space to store it.
Static Linking and Static Libraries is the result of the linker making copy of all used library functions to the executable file. Static Linking creates larger binary files, and need more space on disk and main memory.
gcc -lsome_dynamic_lib code.c some_static_lib.a
You could also use ld
option -Bdynamic
gcc <objectfiles> -static -lstatic1 -lstatic2 -Wl,-Bdynamic -ldynamic1 -ldynamic2
All libraries after it (including system ones linked by gcc automatically) will be linked dynamically.
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