Insights into building shared lib

Hello,

I want to build a shared lib (incl. Boost dependencies). In my CMakeLists.txt I can add this:

add_library(<name> [STATIC | SHARED | MODULE]


But I don't understand the difference between SHARED and MODULE.

I actually want to call the library from a programming language like Perl or Python. I saw SWIG can be used for this, but I am a bit lost on what needs to be done for the linkage.

Thanks a lot!

STATIC puts the code in a .a that gets statically linked when you build the executable.

SHARED puts the code in a .so that gets dynamically linked at run time, and generates a .a that gets statically linked and tells the execution environment how to link to the .so (what its name is, which symbols are used, etc.)

MODULE is the same as SHARED, except it doesn't generate the .a. The caller process is expected to call dynamic loading functions (e.g. dlopen()) to load the .so and then query the loaded module for specific symbols.

For your use case, MODULE is the most appropriate, since you can't link to a .a from a scripting language, but either should work just fine.
Last edited on
Registered users can post here. Sign in or register to post.