libtool: Modules for libltdl
1
1 11.2 Creating modules that can be 'dlopen'ed
1 ============================================
1
1 Libtool modules are created like normal libtool libraries with a few
1 exceptions:
1
1 You have to link the module with libtool's '-module' switch, and you
1 should link any program that is intended to dlopen the module with
1 '-dlopen MODULENAME.LA' where possible, so that libtool can dlpreopen
1 the module on platforms that do not support dlopening. If the module
1 depends on any other libraries, make sure you specify them either when
1 you link the module or when you link programs that dlopen it. If you
1 want to disable versioning (⇒Versioning) for a specific module
1 you should link it with the '-avoid-version' switch. Note that libtool
1 modules don't need to have a "lib" prefix. However, Automake 1.4 or
1 higher is required to build such modules.
1
1 Usually a set of modules provide the same interface, i.e. exports the
1 same symbols, so that a program can dlopen them without having to know
1 more about their internals: In order to avoid symbol conflicts all
1 exported symbols must be prefixed with "modulename_LTX_" (MODULENAME is
1 the name of the module). Internal symbols must be named in such a way
1 that they won't conflict with other modules, for example, by prefixing
1 them with "_modulename_". Although some platforms support having the
1 same symbols defined more than once it is generally not portable and it
1 makes it impossible to dlpreopen such modules.
1
1 libltdl will automatically cut the prefix off to get the real name of
1 the symbol. Additionally, it supports modules that do not use a prefix
1 so that you can also dlopen non-libtool modules.
1
1 'foo1.c' gives an example of a portable libtool module. Exported
1 symbols are prefixed with "foo1_LTX_", internal symbols with "_foo1_".
1 Aliases are defined at the beginning so that the code is more readable.
1
1 /* aliases for the exported symbols */
1 #define foo foo1_LTX_foo
1 #define bar foo1_LTX_bar
1
1 /* a global variable definition */
1 int bar = 1;
1
1 /* a private function */
1 int _foo1_helper() {
1 return bar;
1 }
1
1 /* an exported function */
1 int foo() {
1 return _foo1_helper();
1 }
1
1 The 'Makefile.am' contains the necessary rules to build the module
1 'foo1.la':
1
1 ...
1 lib_LTLIBRARIES = foo1.la
1
1 foo1_la_SOURCES = foo1.c
1 foo1_la_LDFLAGS = -module
1 ...
1