libtool
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lt_dlopen an uninstalled library


From: ilya Basin
Subject: lt_dlopen an uninstalled library
Date: Mon, 22 Nov 2021 23:33:14 +0300
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2

Hi List.
I'm making a program with plugins as shared libraries and when I run `make 
check` I want my program to load the uninstalled plugins using lt_dlopen().

I expected that passing `-dlopen libname.la` to libtool would force the 
generation of a wrapper script setting the proper LD_LIBRARY_PATH (just like 
regular linking with a shared .la does). However, an ELF binary is generated 
and and attempt to call lt_dlopen("libname.la") fails with "File not found". It 
only succeeds if the filename contains "./.libs/". What am I doing wrong?

Makefile.am:

    bin_PROGRAMS = purplecat
    purplecat_SOURCES = main.c
    
    purplecat_LDADD = \
        -dlopen libpurplecat.la \
        -lltdl \
        $(MY_NULL)
    
    lib_LTLIBRARIES = libpurplecat.la
    
    libpurplecat_la_SOURCES = \
        purplecat.h \
        purplecat.c \
        $(MY_NULL)
    
    libpurplecat_la_LDFLAGS = -module


main.c:

    int main(int argc, char *argv[]) {
        static const char *filename = "libpurplecat";
        static int (*p_pcat_main)(int argc, char *argv[]);
        int res;
        lt_dlinit();
        lt_dlhandle handle = lt_dlopenext(filename);
        if (!handle) {
                fprintf(stderr, "Failed to load '%s': %s\n", filename, 
lt_dlerror());
                return 1;
        }
        p_pcat_main = lt_dlsym(handle, "pcat_main");
        res = p_pcat_main(argc, argv);
        lt_dlclose(handle);
        return res;
    }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]