0

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

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)

unname -a

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_release -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

怎么了?

提前致谢!

4

1 回答 1

3

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

问题似乎是你有 32-bit libstdc++.a,但不是 64-bit 。

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

如果没有提供 64 位的现有软件包libstdc++.a(这不太可能),您可以获取 RPM 的源 RPM gcc,然后重新构建它。这应该会给你一个可用的 64 位版本的libstdc++.a.

于 2013-02-02T03:04:40.930 回答