avatar
help on building shared object# Unix - 噫吁兮,危乎高哉
i*o
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
avatar
m*m
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");

avatar
T*r
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");

avatar
i*o
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

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。