Red Hat Bugzilla – Bug 233730
Statically linking to libstdc++.a does not work
Last modified: 2008-08-02 19:40:34 EDT
Description of problem:
Regression, statically linking to libstdc++ is broken.
Version-Release number of selected component (if applicable):
gcc 4.1.1 (20070105)
Steps to Reproduce:
1. Write a simple C++ program
2. Compile it into a dynamic library, one option to use is -Wl -Bstatic -lstdc++
-Wl -Bdynamic -l < the rest of dependent libraries..>
3. gcc fails with lstdc++, not found
gcc fails with lstdc++ not found
gcc should pass.
This certainly works for me just fine.
You really need to give more details:
1) rpm -q gcc gcc-c++ libstdc++ libstdc++-devel
2) the exact command line you tried to run
3) the error messages you got
libstdc++.a is in
rpm -qplv libstdc++-devel-4.1.1-51.fc6.x86_64.rpm 2>/dev/null | fgrep libstdc++.a
-rw-r--r-- 1 root root 2650764 Jan 6 14:25
If you are trying to gcc -shared ... -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic, then
that's really not expected to work (because libstdc++.a is not PIC), but the
errors wouldn't be about libstdc++ which couldn't be found, but about trying
to link non-PIC objects into a shared library on x86_64.
1. rpm -q gcc gcc-c++ libstdc++ libstdc++-devel
2. The exact command:
g++ -m32 -march=i586 -c -o foo.o foo.cpp
gcc -shared -static-libgcc -o libfoo.so foo.o -Wl,-Bstatic -lstdc++ -Wl,
-Bdynamic -lm -ldl
3. the error messages you got
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
4. gcc -print-file-name=libstdc++.a
You have just the 64-bit libstdc++-devel installed, then of course you can't
expect to find the 32-bit libstdc++.a. rpm Requires can't be used for this,
because not everybody needs/wants 32-bit capable gcc/g++/... on x86_64.
So, just yum install libstdc*-devel.i386 and also make sure you pass
-m32 even on the link line (otherwise it has no chance to work right, you are
handing it a 32-bit object and request 64-bit library to be created from it.