brooks94
brooks94

Reputation: 3936

Linking shared library against static library

I have two autotools-based projects AAA and BBB:

I'm getting the following when trying to compile BBB:

/usr/bin/ld: /usr/local/lib/libAAA.a(liboAAA_la-foo.o): relocation R_X86_64_PC32 against undefined symbol `malloc@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value

For reference, the actual command that's generating the error is:

gcc -shared  -fPIC -DPIC  .libs/libBBB_la-BBB.o .libs/libBBB_la-hash.o .libs/libBBB_la-vl_helpers.o   -lm -L/usr/local/lib /usr/local/lib/libAAA.a  -O3   -Wl,-soname -Wl,libBBB.so.0 -o .libs/libBBB.so.0.0.0

What am I doing wrong, and how do I make this work?

Upvotes: 3

Views: 1812

Answers (1)

Fred Foo
Fred Foo

Reputation: 363467

libAAA should be built with -fPIC to get position-independent code. In the current setup, you're trying to build a mixed PIC/non-PIC libBBB, which is not allowed.

Upvotes: 5

Related Questions