Receive “undefined symbol” error when loading library with dlopen

后端 未结 3 1195
梦毁少年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:09

    I've found the answer myself.

    I had to add the --export-dynamic flags to the link options for the main executable.

    When creating a dynamically linked executable, add all symbols to the dynamic symbol table. The dynamic symbol table is the set of symbols which are visible from dynamic objects at run time.

    If you do not use this option, the dynamic symbol table will normally contain only those symbols which are referenced by some dynamic object mentioned in the link.

    If you use "dlopen" to load a dynamic object which needs to refer back to the symbols defined by the program, rather than some other dynamic object, then you will probably need to use this option when linking the program itself.

提交回复
热议问题