Search code examples
cdlopen

Why plugin dynamic library can't find the symbol in the application?


I have an application, which has been compiled several libraries into it through static link.

And this application will load a plugin through dlopen when it runs.

But it seems that the plugin can't resolve the symbol in the application, which I can find them through "nm".

So what can I do? Recompile the libraries into shared mode, and link them to the plugin?


Solution

  • You have to use the gcc flag -rdynamic when linking your application, which exports the symbols of the application for dynamic linkage with shared libraries.

    From the gcc documentation:

    Pass the flag -export-dynamic to the ELF linker, on targets that support it. This instructs the linker to add all symbols, not only used ones, to the dynamic symbol table. This option is needed for some uses of dlopen or to allow obtaining backtraces from within a program.

    This should eliminate your problem.