Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 233730 - Statically linking to libstdc++.a does not work
Summary: Statically linking to libstdc++.a does not work
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: rawhide
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2007-03-24 05:13 UTC by Xiaobin Lu
Modified: 2008-08-02 23:40 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2007-03-27 10:08:04 UTC


Attachments (Terms of Use)

Description Xiaobin Lu 2007-03-24 05:13:39 UTC
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 08:17:59 UTC
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
/usr/lib/gcc/x86_64-redhat-linux/4.1.1/libstdc++.a

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 17:50:36 UTC
1. rpm -q gcc gcc-c++ libstdc++ libstdc++-devel

gcc-4.1.1-51.fc6
gcc-c++-4.1.1-51.fc6
libstdc++-4.1.1-51.fc6
libstdc++-4.1.1-51.fc6
libstdc++-devel-4.1.1-51.fc6

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
output:
/usr/lib/gcc/x86_64-redhat-linux/4.1.1/libstdc++.a

Comment 3 Jakub Jelinek 2007-03-27 10:08:04 UTC
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.