Search code examples
automakelibtool

libtool: what is the path to my module?


I am creating a module from an autotools+libtool project: The Makefile.am looks as follows

#the module:                                                     
lib_LTLIBRARIES = mmmm.la                                        
mmmm_la_SOURCES = mmmm.c                                 
mmmm_la_LDFLAGS = $(AM_LDFLAGS) -module -shared

Now, I want to write a C test for my module. The test should start loading the shared object mmmm.xx (where .xx is .so or .la)

What path should I give to dlopen() or lt_dlopen() in my C test?: The relative location of my module (compared to the test program) is different depending on whether I do make check, an out of tree make check, or a make installcheck...

I tried with lt_dlopen() hoping that the -dlopen option passed on the test Makefile.am would help autotools to locate the lib when lt_dlopen() is called, but it does not seem to help: lt_dlopen() can open the .la file, indeed, but one still have to tell where that file is located (possibly ommiting the .libs directory)

My test makefile looks like this when testing with the ltdl lib:

#the module test (tests are also installed, hence the "test" prefix)
test_PROGRAMS = tttt
tttt_SOURCES = tttt.c
tttt_LDADD = "-dlopen" mmmm.la
tttt_DEPENDENCIES = mmmm.la

Any good hint?


Solution

  • One way you can deal with that is to set up the LD_LIBRARY_PATH env variable to where your library will be installed.

    However, since you need it for the tests I will say export a variable from the configure.ac to the config.h. Thus, any file including the config.h would have a #define your_variable which can be used to set up the path for dlopen.