C++ 链接libstdc&x2B+;关于RHEL 5.7的问题

C++ 链接libstdc&x2B+;关于RHEL 5.7的问题,c++,linker,g++,libstdc++,C++,Linker,G++,Libstdc++,我想使用以下命令创建静态链接的二进制文件: g++ -o bin/target_binary objs/obj1.o objs/obj2.o objs/obj3.o -I/usr/include/c++/4.1.1/ -O3 -Wall -static -static-libstdc++ -static-libgcc -L /usr/lib/gcc/x86_64-redhat-linux/4.1.1/32 -Wl,-verbose 输出的相关部分: attempt to open /usr/l

我想使用以下命令创建静态链接的二进制文件:

g++ -o bin/target_binary objs/obj1.o objs/obj2.o objs/obj3.o -I/usr/include/c++/4.1.1/ -O3 -Wall -static -static-libstdc++ -static-libgcc -L /usr/lib/gcc/x86_64-redhat-linux/4.1.1/32 -Wl,-verbose
输出的相关部分:

attempt to open /usr/lib/gcc/x86_64-redhat-linux/4.1.1/32/libstdc++.a succeeded
attempt to open /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libstdc++.a failed
attempt to open /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libstdc++.a failed
attempt to open /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libstdc++.a failed
attempt to open /lib/../lib64/libstdc++.a failed
attempt to open /usr/lib/../lib64/libstdc++.a failed
attempt to open /usr/x86_64-redhat-linux/lib64/libstdc++.a failed
attempt to open /usr/local/lib64/libstdc++.a failed
attempt to open /lib64/libstdc++.a failed
attempt to open /usr/lib64/libstdc++.a failed
attempt to open /usr/x86_64-redhat-linux/lib/libstdc++.a failed
attempt to open /usr/lib64/libstdc++.a failed
attempt to open /usr/local/lib/libstdc++.a failed
attempt to open /lib/libstdc++.a failed
attempt to open /usr/lib/libstdc++.a failed
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.1.1/32/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
g++-v

Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --disable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-51)
联阿援助团

Linux vmh-caipi-reporting.lsy.fra.dlh.de 2.6.18-274.18.1.el5 #1 SMP Fri Jan 20 15:11:18 EST 2012 x86_64 x86_64 x86_64 GNU/Linux
lsb_发布-a

LSB Version:    :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 5.7 (Tikanga)
Release:    5.7
Codename:   Tikanga
怎么了

提前谢谢

/usr/bin/ld:找不到-lstdc++

问题似乎是您有32位
libstdc++.a
,但没有64位

找出32位版本的来源:
rpm-qf/usr/lib/gcc/x86_64-redhat-linux/4.1.1/32/libstdc++.a
,并尝试安装等效的64位软件包

如果没有提供64位
libstdc++.a
(这不太可能),您可以获取
gcc
的源RPM,然后重新构建它。这将为您提供一个可用的64位版本的
libstdc++.a

/usr/bin/ld:找不到-lstdc++

问题似乎是您有32位
libstdc++.a
,但没有64位

找出32位版本的来源:
rpm-qf/usr/lib/gcc/x86_64-redhat-linux/4.1.1/32/libstdc++.a
,并尝试安装等效的64位软件包


如果没有提供64位
libstdc++.a
(这不太可能),您可以获取
gcc
的源RPM,然后重新构建它。这将为您提供一个可用的64位版本的
libstdc++。a

Hmm,gcc版本历史似乎意味着
-静态libstdc++
从4.5.0开始就被包括在内,这比您的4.1.2整整新了3年。也许你应该考虑GCC升级?不幸的是,我不允许改变OS上的任何东西。在这种情况下,你应该试试HMM的教程,GCC版本历史似乎意味着<代码>静态LBSTDC++/<代码>已经被包括4.5.0,这比你的4.1.2更新了整整3年。也许你应该考虑GCC升级?不幸的是,我不允许改变OS上的任何东西。在这种情况下,你应该尝试教程。不幸的是,我不允许改变OS上的任何东西,但通常情况下,这将解决这个问题,我想。谢谢您的提示。@bayerb构建您自己的libstdc++.a不需要在操作系统中更改任何内容。不幸的是,我不允许在操作系统上更改任何内容,但我认为这通常可以解决问题。感谢您的提示。@bayerb构建您自己的libstdc++.a不需要在操作系统中进行任何更改。