Re: lt_dlopen an uninstalled library

2021-11-22 Thread Luke Mewburn
On 21-11-22 23:33, ilya Basin wrote:
  | 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?


I think you'll find it's less hassle to extend your testsuite setup to
install the library into the testsuite working area before performing
other tests, using a "make DESTDIR=working/area/some/subdir install".
I do this for other components too, such as python extension shared
libraries.

Then just set your LD_LIBRARY_PATH, PYTHONPATH (etc) to the
relevant testsuite working area, before running the other tests.


  | 
  | 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;
  | }
  | 



regards,
Luke.



lt_dlopen an uninstalled library

2021-11-22 Thread ilya Basin
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;
}