7

I am facing below errors when trying to statically link libDuma, Can you tell me how to ask g++ to use malloc from libDuma?

sunny@sunny-laptop:~/CodeTest$ g++ ./testDuma.cpp -g  -o testDuma -static -lduma -pthread
/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/libc.a(malloc.o): In function `free':
(.text+0x4b00): multiple definition of `free'
/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/libduma.a(duma.o):(.text+0x25f0): first defined here
/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/libc.a(malloc.o): In function `malloc':
(.text+0x4bc0): multiple definition of `malloc'
/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/libduma.a(duma.o):(.text+0x2730): first defined here
/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/libc.a(malloc.o): In function `realloc':
(.text+0x5950): multiple definition of `realloc'
/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/libduma.a(duma.o):(.text+0x23d0): first defined here
collect2: ld returned 1 exit status
4

2 に答える 2

3

完全に静的なリンクを強制しないでください(-staticフラグを使用しないでください)。最近のUNIXシステムでこれを行うことは、非常に悪い考えです(TM)。

代わりに、libdumaだけを静的にリンクします。これらのコマンドのいずれかが機能するはずです。

g++ ./testDuma.cpp -g -pthread -o testDuma /path/to/libduma.a
g++ ./testDuma.cpp -g -pthread -o testDuma -Wl,-Bstatic -lduma -Wl,-Bdynamic
于 2011-05-22T05:01:11.340 に答える
1

Add -nodefaultlibs flag to not link to libc. Or, remove -lduma and link it dynamically after compilation with:

LD_PRELOAD=/usr/lib/libduma.so ./testDuma
于 2011-05-21T10:04:22.560 に答える