user1159290
user1159290

Reputation: 1003

proper handling of plugins (modules) in autotoos/libtool

I have a project that generates a static lib L. Some function of L has the ability to load some pluggins M (using dlopen("libmmmm.so"): M is a shared lib (module)).

The test T testing the module_load() function of L is made of the main test T (to which L is staticaly linked) and a pluggin M, to test its loading in T+L.

The tests are part of the installation (testdir is defined).

Here follows the Makefile.am in test T's directory (building both T and M):

#the test program linked with the static lib L:   
#(the tests are distributed as well, hence the test_* prefix)                                  
test_PROGRAMS = tttt                                       
tttt_SOURCES = tttt.c
tttt_LDADD = llll.la

#the module to be loaded by the T+L test:                                                     
lib_LTLIBRARIES = libmmmm.la                                        
libmmmm_la_SOURCES = mmmm.c                                 
libmmmm_la_LDFLAGS = $(AM_LDFLAGS) -module -shared  

The problem is regarding the path at which the module can be found: The test works (i.e. libmmmm.so is found) for make check. But fails for out of tree (VPATH) builds (shared lib not found).

So the question: How is it supposed to work? libtool has to set something like LD_LIBRARY_PATH, I guess, as dlopen() will never understand the *.la wrapper...

So what does it do and how can I fix this so it works all times, i.e. make check, out of tree build, make distcheck... Hard coding a search path into the .libs directory does not feel very portable: We use autotools because we target many different platforms.

PS: I am aware that the "lib" prefix of M could be omitted due to the "-module" option

Upvotes: 1

Views: 182

Answers (1)

Diego Elio Pettenò
Diego Elio Pettenò

Reputation: 3240

You could use libltdl to take care of it, that one does understand .la files, and that will fix the loading, but it's not 100% the same API.

I'm afraid that otherwise, you'll have to write your own wrapper scripts to set LD_LIBRARY_PATH in this situation.

Upvotes: 2

Related Questions