【问题标题】:Getting GMP to work with GCC 4.5.2让 GMP 与 GCC 4.5.2 一起工作
【发布时间】:2011-03-01 10:28:19
【问题描述】:

我正在尝试使用来自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

【问题讨论】:

    标签: linux gcc gmp


    【解决方案1】:

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

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

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

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

    编辑:

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

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

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

    底线是:

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

    • 为您的构建主机编译库,即 MacOSX/x86_64。这意味着在其配置调用的任何--host 选项中,您应该与--host=x86_64-darwin (或您的主机需要的任何东西)类似。如果 configure 可以自己找出主机,则可以完全跳过 --host 选项。

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

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

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

    【讨论】:

    • 我有点糊涂,你能举个例子吗
    • @thkala 也不允许设置 --target?
    • @thkala 我试过“./configure --prefix=/gmp1 --host=i386-apple-darwin10.6.0 --build=i386-linux --with-gmp=/gmp1 -- with-mpfr=/gmp1" 但它出现了上述错误(如问题中所述)
    • @Daniel:gmp、mpfr 和 mpc 需要为您的构建主机编译 - 只需像编译 Darwin 的任何其他库一样编译它们。 --target 对他们没有意义。只有 GCC 有目标选项。
    • 我仍然很困惑,我之前尝试过 ./configure --prefix=/gmp1 并且它出现了“/gmp1/lib/lib.gmp.dylib,文件是为不受支持的文件格式构建的这不是被链接的架构(i386)“
    【解决方案2】:

    您在编译 GMP 时是否使用了“ABI=32”选项?如果不是,我认为即使主机/目标指定为 i386,它也会使用 64 位代码。

    【讨论】:

      猜你喜欢
      • 2023-03-07
      • 1970-01-01
      • 2016-12-13
      • 2016-10-06
      • 2011-11-30
      • 2014-02-19
      • 2011-09-03
      • 2013-05-01
      • 2018-05-30
      相关资源
      最近更新 更多