Shuzheng
Shuzheng

Reputation: 13850

Do shared libraries (.so) files need to present (or specified) at link time?

Do shared libraries (.so) files need to present (or specified) at link time?

I've read here (Difference between shared objects (.so), static libraries (.a), and DLL's (.so)?) that .so files must be present at compile time, but in my experience this is not true?

Doesn't shared libraries just get linked at runtime using dlopen and dlsym, so that the library may not be present on the system, when the application is linked?

Upvotes: 13

Views: 5401

Answers (2)

Most shared libraries need to be present both at build time and at run time. Notice that shared libraries are not DLLs (which is a Windows thing).

I assume you code for Linux. Details are different on other OSes (and they matter).

For example, if you are compiling a Qt application, you need the Qt shared libraries (such as /usr/lib/x86_64-linux-gnu/libQt5Gui.so and many others) both when building your application and when running it. Read about the dynamic linker ld-linux.so(8) & about ELF.

But you are asking about dynamic loading (using dlopen(3) with dlsym(3) ...) of plugins. Then read Levine's Linkers & Loaders, Program Library HowTo, C++ dlopen mini HowTo, and Drepper's How To Write Shared Libraries

See also this answer.

Some libraries and frameworks try to abstract the loading of plugins in an OS-neutral manner. Read e.g. about Qt plugins support, or about POCO shared libraries (poorly named, it is about plugins).

Upvotes: 7

hyphen
hyphen

Reputation: 509

You can have it both way, it all works.

While with library present at compile time,instead of get library by dlopen/LoadLibrary explictly, you can use all the functions directly

Upvotes: 0

Related Questions