Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gfortran: compiling 32-bit executable in 64-bit system

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.

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

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.

Thank you in advance!

like image 705
pamgur Avatar asked Feb 04 '15 14:02

pamgur


People also ask

Is gcc 32 bit compiler?

Mostly compiler(gcc or clang) of C and C++, nowadays come with default 64-bit version.

How can I tell if gcc is 32 or 64 bit?

To check this, we have to type this command. gcc –v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu ........... ........... ...........

Does Windows have a Fortran compiler?

The Windows Fortran compiler supports a full range of project targets including command-line programs, GUI based applications, and Window's DLLs.

What is m32 in C?

-m32 is there to compile 32 bits objects on a compiler configured to compile 64 bits objects by default.


1 Answers

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

Now gfortran -m32 foo.f should work.

like image 172
nathanielng Avatar answered Sep 28 '22 11:09

nathanielng