fredd
May 20, 2004, 7:26pm
1
Hi all
so far i got always the same problem when i try to use the DLL in a C application. When it reach the line
if ((handle = dlopen("/fred/libresource.so", RTLD_NOW)) == NULL)
{
perror(“dlopen”);
printf(“dlerror: %sn”, dlerror());
exit(1);
}
i got a segmentation fault.
so far, i’ve tryed add these line in either makefile or common.mk
CFLAGS+=-shared
LDFLAGS+=-shared -Wl,-Bsymbolic
SDFLAGS+=-shared -Wl,-Bsymbolic
the compilation is successful and i see a puzzle piece picture as icon before the name of my executable release.
in my library i use
ApAddContext(&AbContext,"/fred/libresource.so");
when i rename my library file (libresource.c) in a .dll, i got a valid pointer from the function dlopen. Is there something missing for the linker or in my library ?
any help would be appreciate.
Fred
fredd
May 28, 2004, 7:38pm
2
The Solution is :
make the correction that i have mentionned in the thread Setting up Linker’s Option…
after that :
check export all symbols in the linker’s options. Select the type of library (probably shared .so & .a)
In the DLL you have to write an Initialisation function :
int InitDLL(int argc, char* argv[]){
ApAddContext(&AbContext,“Path to the library”);
…
}
and a Cleanup function :
int CleanDLL(int argc, char *argv[]){
ApRemoveContext(&AbContext);
…
}
in the application :
void library_handle;
typedef int (dllfunc)(int, char );
dllfunc InitDll, CleanDll;
if((library_handle = dlopen(“Path to the library”,RTLD_NOW)) == NULL){
…
exit(1);
}
if((InitDll = dlsym(library_handle,“InitDll”)) == NULL){
…
exit(1);
}
(*InitDll)(argc,argv);
use your functions…
then cleanup
if ((CleanDll = dlsym(library_handle,“CleanDll”)) == NULL){
…
exit(1);
}
(*CleanDll)(argc,argv);
dlclose(library_handle);
Fred