Take the 2-minute tour ×

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

share|improve this question
You 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 use ldd on the binary to determine its runtime linker dependencies. –  birryree Nov 25 '10 at 22:56
Can I specify want library should be linked statically? –  TheFuzz Nov 25 '10 at 22:59
you can selectively static link by passing the full name of the library. Like gcc -o OutFile <source files> -l:libclsocket.a. Note the :, it is very important. I would like to find out official documentation for this behavior, but gcc's manpages don't mention this use. –  birryree Nov 25 '10 at 23:02
@birryree you said : is very important. What else is it used for? Does gcc automatically used shared libraries? Is -l:<fullLibName.so> good practice? –  TheFuzz Nov 25 '10 at 23:08
if you don't put in the colon, the command doesn't work (for the thing you're trying to do). By default, how gcc links is platform dependent. gcc passes on options to an underlying linker (generally GNU ld on Linux systems, but could be something else on other platforms, like link.exe on Windows, and Sun ld on Solaris), and the linker does its work. By default on Linux/Windows, the underlying linker will attempt dynamic linking, so you don't have to do full-name linking, if you wanted to link to the shared object. –  birryree Nov 25 '10 at 23:14

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
It is linking to the shared libraries. So how would I link to a static lib? I'm also assuming it defaults to shared libraries. –  TheFuzz Nov 25 '10 at 22:56

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.

share|improve this answer

Your Answer


