Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between modules and shared libraries?

The title mostly covers it, what is the difference between a module and a shared library? I just found this distinction in CMake's add_library command, where they say:

SHARED libraries are linked dynamically and loaded at runtime. MODULE libraries are plugins that are not linked into other targets but may be loaded dynamically at runtime using dlopen-like functionality.

But I can load a shared object using dlopen(), can't I?

like image 787
lucas clemente Avatar asked Jan 30 '11 22:01

lucas clemente


People also ask

What is a shared library?

A shared library or shared object is a file that is intended to be shared by multiple programs. Symbols used by a program are loaded from shared libraries into memory at load time or runtime.

What is module in library?

A module is basically a single purpose library. A library contains many modules (a module is usually packaged as a single . jar file). A library can contain many modules, but they are usually all connected by some theme.

What is the difference between shared and static library?

Shared libraries are added during linking process when executable file and libraries are added to the memory. Static libraries are much bigger in size, because external programs are built in the executable file.

What is the use of shared library?

A shared library is an external Java™ archive (JAR) file that is used by one or more applications. Using shared libraries enables multiple applications deployed on a server to use a single library, rather than use multiple copies of the same library.


1 Answers

The difference is that you can link to a SHARED library with the linker, but you cannot link to a MODULE with the linker. On some platforms.

So... to be fully cross-platform and work everywhere CMake works, you should never do this:

# This is a big NO-NO: add_library(mylib MODULE ${srcs}) target_link_libraries(myexe mylib) 

To be fair, on Windows, they're both just dlls, and so this code might actually work. But when you take it to a platform where it's impossible to link to the MODULE, you'll encounter an error.

Bottom line: if you need to link to the library, use SHARED. If you are guaranteed that the library will only be loaded dynamically, then it's safe to use a MODULE. (And perhaps even preferable to help detect if somebody does try to link to it...)

like image 76
DLRdave Avatar answered Oct 29 '22 12:10

DLRdave