Originally posted by: SystemAdmin
Hello,
I am trying to load a shared library with dlopen()
the library seem to be correctly compiled, and the "normal" loading seem OK
The Dynamic loading is made as follow :
the static objects are compiled as follow :
xlC_r -o mmyobj.o -c mysource.c
the shared objexts are compiled as follow :
xlC_r -G -o mysharedobj.so myobj.o -bnoentry -bexpall -lc
the library is packaged as follow
ar r mylib.a mysharedobj.so
my executable is generated as follow :
xlC_r -o main.o -c main.c
xlC_r -o program main.o
in the main.c, I try to load the lib dynamically with dlopen() :
void * handle;
void (* DisplayD)(int);
handle = dlopen("malib.a",RTLD_LAZY|RTLD_GLOBAL);
if(handle == NULL)
{
printf(dlerror());
return;
}
if( DisplayD = (void (*) (int))dlsym(handle,"testfunction") )
{
(*DisplayD )(1);
}
dlclose(handle)
everything compiles well, but when executing, I get the message :
could not load module mylib.a
the module has an invalid magic number
if I try to open mysharedobj.so instead of mylib.a, everything works fine, but I need to work with libraries because of project's writing rules
I have tried to load the library "normally", by modificating a bit my source code only in my main.c and compiling it by
xlC_r -o main.o -c main.c -Iinclude
xlC_r -o program mylib.a main.o
everything works well, so I suppose my lib is correct
I guess my error is in the use of the ar command, but I don't know what is correct
does anyone have an idea about it?
any help would be welcome
thanks
Sebastien
#AIX-Forum