Receive “undefined symbol” error when loading library with dlopen

后端 未结 3 1201
梦毁少年i
梦毁少年i 2020-12-13 07:51

I\'m writing some code that uses dynamic shared libraries as plugins.

My command line for building the shared libraries looks like:

cc -shared -fPIC          


        
3条回答
  •  长情又很酷
    2020-12-13 08:20

    Correct solution is to add -rdynamic to the link command of the main executable. This will add appropriate option to ld (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).

提交回复
热议问题