让GMP与GCC 4.5.2一起使用

Dan*_*iel 2 linux gcc gmp

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

我在Intel Mac(10.6.6,x86_64)我编译:gmp,mpfr,mpc为交叉编译器为32bit(因为我在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)
Run Code Online (Sandbox Code Playgroud)

在编译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
Run Code Online (Sandbox Code Playgroud)

另外,如果我用以下方法编译GMP:

./configure --prefix=/gmp1 --host=i386-linux
Run Code Online (Sandbox Code Playgroud)

我明白了:

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
Run Code Online (Sandbox Code Playgroud)

thk*_*ala 6

我认为你很困惑应该为哪个平台编译哪个包:

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

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

通常,只有在GCC编译的程序中链接的库才需要为交叉编译器目标(例如i386-linux)构建.GMP和MPFR不是这样的库,除非你的程序实际使用它们 - 在这种情况下,你需要有两个这样的库副本,一个用于GCC,一个用于目标的交叉构建.

编辑:

您考虑过使用MacPorts吗?它具有交叉编译器的所有依赖关系:

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

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

底线是:

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

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

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

另请参阅本教程.它有一些关于如何使用适当的glibc生成工作工具链的信息.

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