Undefined symbol when trying to load a library with dlopen

Luca Carlon picture Luca Carlon · Dec 3, 2011 · Viewed 14.7k times · Source

I'm trying to load a shared library (plugin) I was provided (closed source) with dlopen under a Linux ARM platform. I'm trying to load this way:

void* handle = dlopen(<library_path>/<library_name>, RTLD_NOW);

The result is a failure with this message:

Failed to load <library_path>/<library_name>: undefined symbol: <symbol_name>.

I tried to look inside the library with nm, but it seems the lib was stripped, no symbol could be found. I also tried using readelf -s, and, in fact, I got this result:

12663: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND <symbol_name>

By reading around, I get that readelf -s returns all the symbols, including those symbols defined in libraries referenced by it.

The answers to this question are not completely clear to me: is this a symbol which is supposed to be in the library and which is not there because it was compiled the wrong way or is this a symbol I'm supposed find somewhere else? The output of readelf -d seems to suggest I'm providing all the needed shared libraries. May this error be related to a mistake in the way I'm compiling my executable or is this something not related to the loader?

Also, I read about the meaning of each column, but those values are quite strange. How do you interpret that symbol description? Why is address 0? Why is type NOTYPE?

Answer

j_kubik picture j_kubik · Dec 3, 2011

undefined symbol: X means always that X should be exported from one of loaded libraries, but it's not. You should find out in which library requested symbol is and link to it.

You should know that this message is always result of problem with library, it's not fault. Library should know how to get all it's symbols. If it doesn't you can link your executable to required library so when you load your plugin, requested symbol is already known.

This error might have more complex reason. In case when both plugin and main app are linking to library, then attempts to link it might end with undefined symbols anyway. This might happen if main app and plugin are using different version of library (namely plugin uses newer one). Then at the point of loading plugin older version is already loaded, so loader assumes everything is ok, but newer version might contain new symbols. If plugin uses them, you will get undefined symbol errors.