linux dlopen can not find static library's sym

2019-09-11 15:57发布

问题:

I have an executable project which uses a shared library, that includes a static library. Then from the executable, I try to load another shared library with dlopen. That library is found but it cannot find symbols from static library.

Here is the structure:

-- SHARED LIB 1
   -- (compiled with) Static Lib 1

-- EXECUTABLE
   -- SHARED LIB 1
   -- dlopen SHARED LIB 2  XX ERROR: SHARED LIB 2 cannot find symbols of Static Lib 1

Both SHARED LIB 1 and SHARED LIB 2 are linked from /usr/lib.

It seems that I miss some flags.

How could I solve this issue?

回答1:

what flags are used to build the "SHARED LIB 1"? AFAIK -fvisibility won't affect static libs.

However if you use --exclude-libs on linking, the "Static Lib 1"s symbol will be removed.

Hope this Question may help: How to apply gcc -fvisibility option to symbols in static libraries?