Why is that?
see earlier post.
In any event, the problem is that when loading C extensions, ruby doesn’t
seem to be respecting the LD_LIBRARY_PATH setting. Regardless of the
probity of the idea, it’s broken, and needs fixing.
it is not ruby which is broken
eg/c > cat liba.c
int a;
eg/c > cat libb.c
int b;
extern int a;
eg/c > gcc -o liba.so -shared liba.c
eg/c > gcc -o libb.so -shared libb.c -L ./ -la
eg/c > ldd liba.so
libc.so.6 => /lib/libc.so.6 (0x4000b000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)
eg/c > ldd libb.so
liba.so => not found
libc.so.6 => /lib/libc.so.6 (0x4000b000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)
so liba.so has NO depends, and libb.so HAS depends.
now a program to dlopen them :
eg/c > cat dlopen.c
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
int
main (int argc, char **argv)
{
char *ld_library_path;
/* set LD_LIBRARY_PATH if arg given */
if (argc > 1)
{
printf ("SET LD_LIBRARY_PATH TO : %s\n", argv[1]);
setenv ("LD_LIBRARY_PATH", argv[1], 0);
}
/* print LD_LIBRARY_PATH if env has it */
if (ld_library_path = getenv ("LD_LIBRARY_PATH"))
{
printf ("LD_LIBRARY_PATH : %s\n", ld_library_path);
}
/* try to open liba.so */
if ((dlopen ("liba.so", RTLD_NOW|RTLD_GLOBAL)) == NULL)
{
printf ("FAILED TO LOAD 'liba.so'\n");
}
else
{
printf ("SUCCESSFULLY LOADED 'liba.so'\n");
}
/* try to open libb.so - which depends on a*/
if ((dlopen ("libb.so", RTLD_NOW|RTLD_GLOBAL)) == NULL)
{
printf ("FAILED TO LOAD 'libb.so'\n");
}
else
{
printf ("SUCCESSFULLY LOADED 'libb.so'\n");
}
return 0;
}
now using it
eg/c > dlopen
FAILED TO LOAD ‘liba.so’
FAILED TO LOAD ‘libb.so’
eg/c > dlopen ./
SET LD_LIBRARY_PATH TO : ./
LD_LIBRARY_PATH : ./
FAILED TO LOAD ‘liba.so’
FAILED TO LOAD ‘libb.so’
eg/c > env LD_LIBRARY_PATH=./ dlopen
LD_LIBRARY_PATH : ./
SUCCESSFULLY LOADED ‘liba.so’
SUCCESSFULLY LOADED ‘libb.so’
so you see, setting LD_LIBRARY_PATH using setenv does not affect dlopen?!
there is probably a reason for this - but it’s non-obvious. using LD_RUN_PATH
or compiling with -rpath always works and is easy to understand and maintain.
it seems as if dlopen uses the environment of the parent process… perhaps
for securtiy? anyone? all i know is that every time i play with dlopen and
LD_LIBRARY_PATH i’ve been confused…
moral : stay awasy from LD_LIBRARY_PATH
-a
···
On 12 Nov 2002, Eric Schwartz wrote:
–
====================================
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================