linux dlopen can not find static library's symbol
Asked Answered
B

1

1

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?

Bela answered 18/9, 2015 at 10:6 Comment(2)
Your second shared library needs to load your static library as a shared library, or be compiled with it as a static library. This vitiates the benefits of making it static.Hemicycle
You have to declare the symbols extern "C" (or you have to use their mangled names). Are you doing that?Telescopy
S
0

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?

Snag answered 18/9, 2015 at 10:35 Comment(2)
don't have neither --exclude-libs nor -fvisibility in any project.Bela
@MertMertce then you should check Galik 's suggestion. besides, any symbol with 'static' prefix won't have external linkage at all.Snag

© 2022 - 2024 — McMap. All rights reserved.