2

Here's my situation

I have a shared library (PIC) foo.so. It uses symbols from bar.a. bar.a is NPIC. So can't be added to link line of foo.so.

foo.so is dynamically loaded from main.C It loads fine but at run time when a symbol from bar.a is used, it exits with unresolved symbol.

2 solutions I have been suggested 1. Compile bar.a PIC and add it to the link line of foo.so 2. Use " -Wl,--whole-archive bar.a -rdynamic" on main.C link line

1 is not possible because bar.a is a third party library. 2 is not possible because we dont' want our symbols to be exported.

Are there any other idioms/solutions to get around this problem?

2 Answers2

0

"1 is not possible because bar.a is a third party".

That does not sound right to me. Any static library can be linked against. That is the idiom to use. Also take a look at this answer and this one

Community
  • 1
  • 1
xtofl
  • 40,723
  • 12
  • 105
  • 192
0

There is one old good idiom. I call it "libgcc.so idiom" because it is often used in normal libgcc build, when you are creating libgcc_s.so from libgcc.a

Take you bar.a and make bar.so with this line:

gcc -shared -o bar.so -Wl,--whole-archive bar.a -Wl,--no-whole-archive

You may need to supply also something like -nostdlib or so.

And now go and link foo.so with this new bar.so

Now all dependencies will be resolved by dynamic linker when foo.so is loaded.

Konstantin Vladimirov
  • 6,791
  • 1
  • 27
  • 36