11

cmake add_library documentation says,

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.

Practically, I can see both SHARED and MODULE type targets generate .so dynamic libraries on Linux. .so libraries are dynamically linked, loaded at runtime and be mapped using dlopen(). How do these two types of targets differ?

sherlock
  • 2,397
  • 3
  • 27
  • 44

1 Answers1

7

The MODULE ones are intended to be loaded using dlopen only. You can't target_link_libraries() to the MODULE library.

As documentation states, MODULE keyword should be used to underline that a library is a plugin of some sort and shouldn't be linked using -l flag.

arrowd
  • 33,231
  • 8
  • 79
  • 110
  • 2
    Which `ELF` flags does `MODULE` correspond to? In other words, which dynamic libraries can't be linked? How does it matter as far as `make` rules are concerned? – sherlock Apr 18 '17 at 07:52
  • IIRC, it is `-rdynamic`. – arrowd Apr 18 '17 at 09:09
  • 4
    Ah, I've misread your question. The module library doesn't have any symbols exported. That why you can't link to it. – arrowd Apr 18 '17 at 10:51