dlopen, cross call each other

来源:互联网 发布:赢商网怎么样知乎 编辑:程序博客网 时间:2024/06/05 20:23

http://stackoverflow.com/questions/480617/receive-undefined-symbol-error-when-loading-libary-with-dlopen

 

main:so reso
        gcc -Wl,--export-dynamic -o main main.c -ldl

so:so.c
        gcc --shared -fPIC -o libso.so $<

reso:reso.c
        gcc --shared -fPIC -o libreso.so $<

 

Correct solution is to add -rdynamic to the link command of the main executable. This will add appropriate option told (which, when using GNU ld, happens to be --export-dynamic).

Adding --export-dynamic directly is technically incorrect: it's a linker option, and so should be added as-Wl,--export-dynamic, or -Wl,-E. This is also less portable than-rdynamic (other linkers have an equivalent, but the option itself is different).

 

0 0