4

I am using ubuntu 12.04 on 64 bit machine, I have this simple C code:

 int b = 20;
 int c = 10;

 int main(int argc, char **argv) {
      c = 50;
 }

I was trying make it compatible with any IA32 machine by compiling it like this:

 unix> gcc -m32 code.c

And got these errors:

 /usr/bin/ld: cannot find crt1.o: No such file or directory
 /usr/bin/ld: cannot find crti.o: No such file or directory
 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/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.6/libgcc_s.so when searching for -lgcc_s
 /usr/bin/ld: cannot find -lgcc_s
 /usr/bin/ld: cannot find -lc
 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/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.6/libgcc_s.so when searching for -lgcc_s
 /usr/bin/ld: cannot find -lgcc_s
 /usr/bin/ld: cannot find crtn.o: No such file or directory
 collect2: ld returned 1 exit status

As I understand, this is happening because I'm missing 32 bit standard C library, so linker cannot link my code against standard C library.

How can I obtain the needed 32 standard C on my 64 bit machine?

nims
  • 3,751
  • 1
  • 23
  • 27
Rustam Issabekov
  • 3,279
  • 6
  • 24
  • 31
  • 1
    possible duplicate of [Cannot find crtn.o, linking 32 bit code on 64 bit system](http://stackoverflow.com/questions/9807581/cannot-find-crtn-o-linking-32-bit-code-on-64-bit-system) – user2284570 Jul 17 '14 at 02:08

1 Answers1

5

Try this:

  apt-get install ia32-libs 

Also, you should compile/link with -m32:

gcc -Wall -pedantic -m32 ...
paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • 1
    Thanks for pointing into right direction, sudo apt-get install libc6-dev-i386 – Rustam Issabekov Jun 17 '12 at 06:24
  • @Rustam Issabekov - cool. Thanx for posting back the complete solution for you! – paulsm4 Jun 17 '12 at 16:52
  • what should I install on a machine with yum ? It says there isn't any anything called `ia32-libs` – gideon Jan 12 '14 at 16:31
  • There is no direct equivalent of ia32-libs for Centos/Fedora/etc. You need to install the appropriate *.686 package(s). EXAMPLE: `yum install compat-libstdc++-296.i686`. Here are more details: https://ask.fedoraproject.org/question/9556/how-do-i-install-32bit-libraries-on-a-64-bit-fedora/ – paulsm4 Jan 13 '14 at 16:40
  • 1
    I got a linker error after this, and had to `sudo apt-get install g++-4.8-multilib` as well – Gordon Williams Jan 20 '16 at 16:00