Bug 233730 - Statically linking to libstdc++.a does not work
Statically linking to libstdc++.a does not work
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
x86_64 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2007-03-24 01:13 EDT by Xiaobin Lu
Modified: 2008-08-02 19:40 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2007-03-27 06:08:04 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Xiaobin Lu 2007-03-24 01:13:39 EDT
Description of problem:

Regression, statically linking to libstdc++ is broken.

Version-Release number of selected component (if applicable):

gcc 4.1.1 (20070105)

How reproducible:

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
Actual results:

gcc fails with lstdc++ not found
Expected results:

gcc should pass.

Additional info:
Comment 1 Jakub Jelinek 2007-03-24 04:17:59 EDT
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.
Comment 2 Xiaobin Lu 2007-03-26 13:50:36 EDT
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
Comment 3 Jakub Jelinek 2007-03-27 06:08:04 EDT
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.

Note You need to log in before you can comment on or make changes to this bug.