linux - 让 GMP 与 GCC 4.5.2 一起工作

标签 linux gcc gmp

我正在尝试使用 http://crossgcc.rts-software.org/doku.php?id=i386linuxgccformac 中的文件制作交叉编译器

我在 Intel Mac(10.6.6,x86_64)上编译:gmp,mpfr,mpc 用于交叉编译器作为 32 位(因为我在 64 位 Mac 上),但我得到了

ld: warning: option -s is obsolete and being ignored
ld: warning: ignoring file /gmp1/lib/libmpc.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file /gmp1/lib/libmpfr.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file /gmp1/lib/libgmp.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

编译 GCC 时:

--prefix=/usr/local/i386-linux-4.5.2 --target=i386-linux --enable-languages=c --without-headers --disable-shared --disable-threads --disable-nls --with-gmp=/gmp1 --with-gmp-lib=/gmp1 --with-gmp-include=/gmp1 --with-mpfr=/gmp1 --with-mpfr-include=/gmp1 --with-mpfr-lib=/gmp1 --with-mpc=/gmp1 --with-mpc-lib=/gmp1 --with-mpc-include=/gmp1

另外,如果我用以下命令编译 GMP:

./configure --prefix=/gmp1 --host=i386-linux

我得到:

configure: WARNING: +----------------------------------------------------------
configure: WARNING: | Cannot determine global symbol prefix.
configure: WARNING: | link -dump -symbols output doesn't contain a global data symbol.
configure: WARNING: | Will proceed with no underscore.
configure: WARNING: | If this is wrong then you'll get link errors referring
configure: WARNING: | to ___gmpn_add_n (note three underscores).
configure: WARNING: | In this case do a fresh build with an override,
configure: WARNING: |     ./configure gmp_cv_asm_underscore=yes
configure: WARNING: +----------------------------------------------------------
checking how to switch to read-only data section... .data
checking for assembler .type directive... 
checking for assembler .size directive... 
checking for assembler local label prefix... configure: WARNING: "link -dump -symbols" failure
configure: WARNING: cannot determine local label, using default L
L
checking for assembler byte directive... .byte
checking how to define a 32-bit word... link: illegal option -- d

最佳答案

我认为您对应该为哪个平台编译哪个包感到困惑:

  • 需要为 x86_64 MacOS X 主机和 i386-linux 目标编译 GCC。

  • GMP、MPC 和 MPFR 是 GCC 的运行时依赖项。因此,它们还需要针对 GCC 主机(在您的情况下为 x86_64)进行编译。因此,GMP配置命令中的--host=i386-linux选项不正确。

一般来说,只有那些将在GCC编译的程序中链接的库才需要为交叉编译器目标(例如i386-linux)构建。 GMP 和 MPFR 不是此类库,除非您的程序实际上正在使用它们 - 在这种情况下,您将需要此类库的两份副本,一份用于 GCC,一份用于目标的交叉构建。

编辑:

您是否考虑过使用MacPorts ?它具有交叉编译器的所有依赖项:

还有一个针对 i386 的基于 newlib 的较旧交叉编译器:

即使您不想使用这些,您仍然可以查看其 Portfiles 中的构建说明。

底线是:

  • 应用这些库所需的任何补丁 - MacPorts 已经这样做了。

  • 为您的构建主机编译库,即 MacOSX/x86_64。这意味着在其配置调用的任何 --host 选项中,您应该遵循 --host=x86_64-darwin (或您的主机需要的任何内容)。如果 configure 可以自行确定主机,则可以完全跳过 --host 选项。

  • 使用 --host 编译 GCC 作为您的构建主机(64 位 Mac OS X)和 i386-linux 的目标,例如--target=i386-linux。如果我是您,我会从仅适用于 C 和 C++ 语言的编译器开始。

另请参阅this tutorial 。它提供了一些有关如何使用适当的 glibc 生成工作工具链的信息。

也就是说,出于多种原因,我认为您最好在虚拟机中安装适当的 Linux 发行版。您是否有理由特别需要交叉编译器?您想用该编译器做什么?

关于linux - 让 GMP 与 GCC 4.5.2 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5153231/

相关文章:

c++ - 如何在 Linux CentOS 上更改默认 GCC 编译器以与 MPI 一起使用

Python virtualenv -> venv/bin/python 中的新 python 可执行文件

c - GCC:禁止使用某些寄存器

c++ - 交叉编译Qt for ARM时出错

linux - 使用 Android NDK 构建的 native 可执行文件与使用 gcc-arm for Raspbian(pi-tools)为 Raspberry Pi 构建的本地可执行文件有何不同

c++ - 当 C++ 从函数的返回值将元素存储到 std::vector 时出现意外结果

c - 从 void 指针转换为 char 指针时遇到问题

c - X86-64 C 内联汇编(使用 GCC 编译),多精度乘法例程导致段错误

android - 从 Android NDK 在 gcc 中交叉编译 gmp,无法执行 ./gen-fac_ui

linux - 如何检查手册页是否存在?