gfortran:在 64 位系统中编译 32 位可执行文件 [英] gfortran: compiling 32-bit executable in 64-bit system
问题描述
我在 AMD Athlon(tm) 64 X2 双核处理器 5200+ ×2 上运行 Ubuntu 12.10(64 位),Linux 内核 3.5.0-51-generic.我有 GNU Fortran (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2.
I'm running Ubuntu 12.10 (64-bit), with Linux kernel 3.5.0-51-generic, on an AMD Athlon(tm) 64 X2 Dual Core Processor 5200+ ×2. I have GNU Fortran (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2.
我正在尝试将一些代码编译成 32 位可执行文件.我已经检查过我的系统上是否安装了所有需要的库(我在之前在 32 位计算机上编译的程序上运行了 ldd,并下载了缺少的包).我尝试运行 $ gfortran foo.f -m32 -L/lib/i386-linux-gnu,但出现以下错误:
I'm trying to compile some code into a 32-bit executable. I've checked that all the needed libraries are installed on my system (I ran ldd on a program previously compiled on a 32-bit computer, and downloaded the missing packages). I tried running $ gfortran foo.f -m32 -L/lib/i386-linux-gnu, but I get the following errors:
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgfortran.so when searching for -lgfortran
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgfortran.a when searching for -lgfortran
/usr/bin/ld: cannot find -lgfortran
/usr/bin/ld: cannot find -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libquadmath.so when searching for -lquadmath
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libquadmath.a when searching for -lquadmath
/usr/bin/ld: cannot find -lquadmath
/usr/bin/ld: cannot find -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: returned 1 exit status
我检查了/usr/lib/gcc/i686-linux-gnu/4.7 和/usr/lib/gcc/i686-linux-gnu/4.7.2 目录,它们都是空的.
I checked the /usr/lib/gcc/i686-linux-gnu/4.7 and /usr/lib/gcc/i686-linux-gnu/4.7.2 directories, and they are both empty.
你能帮我解决这个问题吗?我做了我的研究,但这是我所能做的.
Can you please help me solve this problem? I did my research but this was as far as I could get.
先谢谢你!
推荐答案
64 位库 /usr/lib/gcc/x86_64-linux-gnu/...
不适用于你的 32 位编译.您需要安装 multilib 编译器包(请参阅 https://help.ubuntu.com/community/InstallingCompilers).例如:
The 64-bit libraries /usr/lib/gcc/x86_64-linux-gnu/...
don't apply to your 32-bit compile. You need to install the multilib compiler packages (see https://help.ubuntu.com/community/InstallingCompilers). For example:
sudo apt-get install gfortran-multilib
现在 gfortran -m32 foo.f
应该可以工作了.
Now gfortran -m32 foo.f
should work.
这篇关于gfortran:在 64 位系统中编译 32 位可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!