Question

My application can be compiled & linked successfully via GCC/G++ 4.4.7, which is shipped with CentOS 6.5.

I wanna static link libstdc++.a via -static-libstdc++ , but it is not supported by 4.4.7. Hence I installed redhat-devtools-1.1 via the following command, upgraded GCC/G++ to 4.7.2

cd /etc/yum.repos.d
wget http://people.centos.org/tru/devtools-1.1/devtools-1.1.repo 
yum --enablerepo=testing-1.1-devtools-6 install devtoolset-1.1-gcc devtoolset-1.1-gcc-c++

Then compile my application with the new toolset, it fails

/opt/centos/devtoolset-1.1/root/usr/bin/c++ -m64   -c -O2 -Iinc -fPIC  -MMD -MP -MF "AutoInit.o.d" -o AutoInit.o AutoInit.cpp
/opt/centos/devtoolset-1.1/root/usr/bin/gcc   -m64   -c -O2 -D_LARGEFILE64_SOURCE=1 -Iinc -std=c99 -fPIC  -MMD -MP -MF "common.o.d" -o common.o common.c
/opt/centos/devtoolset-1.1/root/usr/bin/gcc   -m64   -c -O2 -D_LARGEFILE64_SOURCE=1 -Iinc -std=c99 -fPIC  -MMD -MP -MF "rpc.o.d" -o rpc.o rpc.c
/opt/centos/devtoolset-1.1/root/usr/bin/gcc   -m64   -c -O2 -D_LARGEFILE64_SOURCE=1 -Iinc -std=c99 -fPIC  -MMD -MP -MF "transport_service.o.d" -o transport_service.o transport_service.c
/opt/centos/devtoolset-1.1/root/usr/bin/gcc   -m64   -c -O2 -D_LARGEFILE64_SOURCE=1 -Iinc -std=c99 -fPIC  -MMD -MP -MF "interop.o.d" -o interop.o interop.c
/opt/centos/devtoolset-1.1/root/usr/bin/gcc   -m64   -c -O2 -D_LARGEFILE64_SOURCE=1 -Iinc -std=c99 -fPIC  -MMD -MP -MF "utility.o.d" -o utility.o utility.c
/opt/centos/devtoolset-1.1/root/usr/bin/g++ -o libmq.so AutoInit.o common.o rpc.o transport_service.o interop.o utility.o -L./lib -l:libapr-1.a -l:libcurl.a -l:libjansson.a -static-libgcc -static-libstdc++ -Wl,--start-group -l:libzmq.a -l:libczmq.a -Wl,--end-group -shared -fPIC
/usr/bin/ld: /opt/centos/devtoolset-1.1/root/usr/lib/gcc/x86_64-redhat-linux/4.7.2/libstdc++.a(compatibility.o): relocation R_X86_64_32 against `_ZTIN10__cxxabiv115__forced_unwindE' can not be used when making a shared object; recompile with -fPIC
/opt/centos/devtoolset-1.1/root/usr/lib/gcc/x86_64-redhat-linux/4.7.2/libstdc++.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status

Please do you know how to resolve this problem?

Was it helpful?

Solution

Likely libstdc++.a is compiled without -fPIC so ld prohibites building a shared object with it. http://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/ . Probably you need to recompile libstdc++.a yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top