i*o 发帖数: 149 | 1 To build a shared object( .so file),I used following commond:
gcc -fPIC -shared -o output.so input.c
and foo( ) is a function defined in input.c
In order to call foo, I did following in calling process:
void * handle = dlopen("output.so",RTLD_LAZY);
if((error=dlerror())!=NULL){
fputs(error,stderr);
exit(1);
}
foo = dlsym(handle,"foo");
foo()...
However, I got result:
./output.so: undefined symbol: foo
I am pretty sure the problem is from the shared object output.so which was not | m*******m 发帖数: 182 | 2 Maybe you want to use gnu libtool.
【在 i*o 的大作中提到】 : To build a shared object( .so file),I used following commond: : gcc -fPIC -shared -o output.so input.c : and foo( ) is a function defined in input.c : In order to call foo, I did following in calling process: : void * handle = dlopen("output.so",RTLD_LAZY); : if((error=dlerror())!=NULL){ : fputs(error,stderr); : exit(1); : } : foo = dlsym(handle,"foo");
| T********r 发帖数: 6210 | 3 try this way:
gcc -fPIC -shared -o output.so input.c -ldl -lc
【在 i*o 的大作中提到】 : To build a shared object( .so file),I used following commond: : gcc -fPIC -shared -o output.so input.c : and foo( ) is a function defined in input.c : In order to call foo, I did following in calling process: : void * handle = dlopen("output.so",RTLD_LAZY); : if((error=dlerror())!=NULL){ : fputs(error,stderr); : exit(1); : } : foo = dlsym(handle,"foo");
| i*o 发帖数: 149 | 4
Using command strings output.so, I found the function void foo(void) is
foo_Fv in the shared object.
Thus, we need call
foo = dlsym(handle,"foo_Fv"); instead of
By the way, I am using Redhat 6.2, I don't know why gcc
【在 T********r 的大作中提到】 : try this way: : gcc -fPIC -shared -o output.so input.c -ldl -lc
|
|