Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In linux how can I tell if I'm linking to a static or dynamic library?

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

like image 436
TheFuzz Avatar asked Nov 25 '10 22:11

TheFuzz


People also ask

How do I know if my library is static or dynamic?

What are the differences between static and dynamic libraries? Static libraries, while reusable in multiple programs, are locked into a program at compile time. Dynamic, or shared libraries, on the other hand, exist as separate files outside of the executable file.

What is static linking and dynamic linking in Linux?

By using dynamic linking, you can upgrade the routines in the shared libraries without relinking. This form of linking is the default and no additional options are needed. Static linking means that the code for all routines called by your program becomes part of the executable file.

What is dynamic linking in Linux?

Dynamic linking is the most common method, especially on Linux systems. Dynamic linking keeps libraries modular, so just one library can be shared between any number of applications. Modularity also allows a shared library to be updated independently of the applications that rely upon it.


2 Answers

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.

like image 62
Soo Wei Tan Avatar answered Oct 01 '22 19:10

Soo Wei Tan


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.

like image 43
user502515 Avatar answered Oct 01 '22 18:10

user502515