In linux how can I tell if I'm linking to a static or dynamic library?
Solution 1
You can try running ldd
on the executable and seeing if the accompanying .so is being detected as required in the list of dependencies.
ldd man page is here.
Solution 2
If you use the -static
flag, all components will be made static. And -l
may include shared libraries. So specifying the static library filename (e.g. with /usr/lib/libfoo.a
for example, no -l
prepended), should get you the desired effect.
Related videos on Youtube
TheFuzz
Updated on November 26, 2020Comments
-
TheFuzz over 3 years
I have a static and a dynamic library with the same name: libclsocket.a and libclsocket.so When I specify what library I want to link to i simply enter -lclsocket as the library. My program complies and runs perfectly fine, but what library am I using? the static library or the dynamic library? I want to give my friend my program, and I'm not sure If i need to include the libraries in the release. C++, codelite, pcLinuxOS 2010
-
wkl over 13 yearsYou didn't specify the
-static
flag when building with GCC, so most likely you are linking to the shared object. As @Soo Wei Tan answered, you can useldd
on the binary to determine its runtime linker dependencies.
-
-
TheFuzz over 13 yearsIt is linking to the shared libraries. So how would I link to a static lib? I'm also assuming it defaults to shared libraries.