solaris - 编译 64 位 gcc - elf 类错误
Posted
技术标签:
【中文标题】solaris - 编译 64 位 gcc - elf 类错误【英文标题】:solaris - compile 64bit gcc - elf class error 【发布时间】:2011-03-22 16:12:51 【问题描述】:我正在 solaris 上安装现代版本的 gcc。我编译了gmp、mpfr和mpc,它们都是64位的。当我尝试如下配置 gcc 时,我收到一个错误,抱怨 mpc、mpfr 和 gmp 是错误的 elf 类。什么给了?
./../gcc-4.5.1/configure --prefix=/opt/OurAppDir/gcc --with-gmp=/opt/OurAppDir/gmp --with-mpfr=/opt/OurAppDir/mpfr --with-gnu-as --with-gnu-ld --build=sparc-sun-solaris2.10
checking build system type... sparc-sun-solaris2.10
checking host system type... sparc-sun-solaris2.10
checking target system type... sparc-sun-solaris2.10
checking for a BSD-compatible install... ./../gcc-4.5.1/install-sh -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /usr/bin/sed
checking for gawk... no
checking for mawk... no
checking for nawk... nawk
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for gnatbind... no
checking for gnatmake... no
checking whether compiler driver understands Ada... no
checking how to compare bootstrapped objects... cmp $$f1 $$f2 16 16
checking for objdir... .libs
checking for the correct version of gmp.h... yes
checking for the correct version of mpfr.h... yes
checking for the correct version of mpc.h... yes
checking for the correct version of the gmp/mpfr/mpc libraries... no
configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations. Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/. See also
http://gcc.gnu.org/install/prerequisites.html for additional info. If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files. They may be located in separate packages.
config.log 错误
configure:5474: checking for the correct version of gmp.h
configure:5494: gcc -c -g -O2 -I/opt/OurAppDir/gmp/include -I/opt/OurAppDir/mpfr/include conftest.c >&5
configure:5494: $? = 0
configure:5512: gcc -c -g -O2 -I/opt/OurAppDir/gmp/include -I/opt/OurAppDir/mpfr/include conftest.c >&5
configure:5512: $? = 0
configure:5513: result: yes
configure:5529: checking for the correct version of mpfr.h
configure:5547: gcc -c -g -O2 -I/opt/OurAppDir/gmp/include -I/opt/OurAppDir/mpfr/include conftest.c >&5
configure:5547: $? = 0
configure:5564: gcc -c -g -O2 -I/opt/OurAppDir/gmp/include -I/opt/OurAppDir/mpfr/include conftest.c >&5
configure:5564: $? = 0
configure:5565: result: yes
configure:5582: checking for the correct version of mpc.h
configure:5599: gcc -c -g -O2 -I/opt/OurAppDir/gmp/include -I/opt/OurAppDir/mpfr/include conftest.c >&5
configure:5599: $? = 0
configure:5615: gcc -c -g -O2 -I/opt/OurAppDir/gmp/include -I/opt/OurAppDir/mpfr/include conftest.c >&5
configure:5615: $? = 0
configure:5616: result: yes
configure:5634: checking for the correct version of the gmp/mpfr/mpc libraries
configure:5665: gcc -o conftest -g -O2 -I/opt/OurAppDir/gmp/include -I/opt/OurAppDir/mpfr/include -R/usr/sfw/lib/sparcv9 conftest.c -L/opt/OurAppDir/gmp/lib -L/opt/OurAppDir/m
pfr/lib -lmpc -lmpfr -lgmp >&5
ld: fatal: file /opt/OurAppDir/mpfr/lib/libmpc.so: wrong ELF class: ELFCLASS64
ld: fatal: file /opt/OurAppDir/mpfr/lib/libmpfr.so: wrong ELF class: ELFCLASS64
ld: fatal: file /opt/OurAppDir/gmp/lib/libgmp.so: wrong ELF class: ELFCLASS64
ld: fatal: File processing errors. No output written to conftest
【问题讨论】:
【参考方案1】:使用默认配置行,GCC 不会被构建为 64 位二进制文件,而是 32 位。所以,你需要在 32 位模式下重建 GMP、MPFR 和 MPC,通过强制configure ABI=32
。
或者,您可以使用 sparc64-sun-solarisX
构建三元组配置 GCC。在这种情况下,GCC 网站上有additional instructions。
【讨论】:
谢谢,我尝试使用 --build=sparc64-sun-solaris2.10 配置 GCC,但仍然出现相同的错误。 .so 文件的 eld 类是 ELFCLASS64,所以我不明白为什么如果我提供了构建参数,我仍然会收到此错误。 系统编译器是否也默认生成64位代码?如果没有,您还需要CC='gcc -m64'
或等效项。总而言之,我建议做一个 32 位的,这肯定更简单。【参考方案2】:
构建 64 位应用程序不需要 64 位 gcc 二进制文件。 OpenCSW Solaris 软件包为 32 位编译器提供了 32 位和 64 位目标。
我假设您更关心能够从 gcc 生成 64 位二进制文件,而不是 gcc 本身是 64 位。
同时构建32位和64位目标的方式,需要构建两次gmp,一次32位,一次64位。然后你有以下布局(示例取自包的 pkgmap):
1 f none /opt/csw/include/gmp-32.h 0644 root bin 86213 38841 1316878625
1 f none /opt/csw/include/gmp-64.h 0644 root bin 86218 39139 1316879685
1 f none /opt/csw/include/gmp.h 0755 root bin 159 12880 1316879688
1 f none /opt/csw/include/gmpxx-32.h 0644 root bin 114646 51865 1316878625
1 f none /opt/csw/include/gmpxx-64.h 0644 root bin 114646 51865 1316879685
1 f none /opt/csw/include/gmpxx.h 0755 root bin 163 13360 1316879688
1 s none /opt/csw/lib/libgmp.so=libgmp.so.10.0.2
1 s none /opt/csw/lib/libgmpxx.so=libgmpxx.so.4.2.2
1 s none /opt/csw/lib/libgmp.so.10=libgmp.so.10.0.2
1 f none /opt/csw/lib/libgmp.so.10.0.2 0755 root bin 462552 51359 1316878625
1 s none /opt/csw/lib/sparcv9/libgmp.so.10=libgmp.so.10.0.2
1 f none /opt/csw/lib/sparcv9/libgmp.so.10.0.2 0755 root bin 503424 11223 1316879684
GCC 构建系统足够聪明,可以知道查看 /opt/csw/lib/sparcv9
的 64 位库和查看 /opt/csw/lib
的 32 位库。
gmp.h
头文件是一个包装器,它包含一个#ifdef
语句,包括gmp-32.h
或gmp-64.h
,具体取决于请求的编译模式。
/* Allow 32 and 64 bit headers to coexist */
#if defined __amd64 || defined __x86_64 || defined __sparcv9
#include "gmp-64.h"
#else
#include "gmp-32.h"
#endif
gmp 库是唯一需要这种头文件包装器的库; mpc、mpfr、ppl 和 cloog 库不会根据架构/字长改变头文件。
当你用 64 位目标编译 gcc 时,你会得到一个包含两个 crt1.o 文件的布局:
/opt/csw/lib/gcc/sparc-sun-solaris2.9/4.6.2/crt1.o
/opt/csw/lib/gcc/sparc-sun-solaris2.9/4.6.2/sparcv9/crt1.o
这样,当你传递 -m64 时,gcc 会生成一个 64 位的二进制文件。
【讨论】:
以上是关于solaris - 编译 64 位 gcc - elf 类错误的主要内容,如果未能解决你的问题,请参考以下文章