How To Compile a 32-bit Executable on 64-bit Fedora 19

You know how sometimes you just have to compile and run a 32 bit program on a 64 bit machine, and it’s really annoying that it doesn’t seem to work?

Yeah, me too.

Turns out it’s actually pretty straightforward on Fedora 19.

First of all, you need to use the -m32 build flag. Below I’m using it to compile my program ‘pointers’:

gcc -m32 pointers.c -o pointers

You may run into the following error:

/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory
# include <gnu/stubs-32.h>
^
compilation terminated.

To fix this you need to install the 32 bit glibc-devel package. You can do this by running:

yum install glibc-devel.i686

Next, you might see this error:

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.2/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status

Which means you need to install the 32 bit standard C++ library package. You can do this by running:

yum install libstdc++-devel.i686

Then you can quite happily compile your executable with the -m32 flag, as above:

gcc -m32 pointers.c -o pointers

And, as if by magic, you get a 32 bit exe that runs on your 64 bit machine.

You can use the file command to admire what you’ve made:

[faye@localhost src]$ file pointers
pointers: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), 
for GNU/Linux 2.6.32, BuildID[sha1]=0x39958fed2f5c099ad97fd7512e780066acfb1231, not stripped

9 thoughts on “How To Compile a 32-bit Executable on 64-bit Fedora 19

  1. Hi,

    When doing yum install libstdc++-devel.i686 I get below error.

    No package libstdc++-devel.i386 available

    Could you help on how to get this package?

  2. Try doing:
    1) yum install libstdc++-*.i686
    2) yum install glibc-*.i686
    3) yum install libgcc-*.i686

  3. Hi,
    I want to compile a 32 bit c program in 64 bit machince .It get compiled by

    gcc -lncurses RdAcq_hanle_040814.c -o root

    but when executing it provide inappropriate results.May be due to bit difference.

    when I tried to run the following command
    gcc -m32 -lncurses RdAcq_hanle_040814.c -o root
    it gave me error
    “/usr/bin/ld: skipping incompatible /usr/lib64/libtinfo.so when searching for -ltinfo
    /usr/bin/ld: cannot find -ltinfo
    collect2: ld returned 1 exit status”
    Please help

  4. Also to mention the OS is Fedora 16 64 bit.But the result I want is irespective of OS and dependant on 64 bit.
    Thanks in advance

  5. i am also suffering from same error when using lex.
    the output as follows:
    [root@localhost exam2015]# lex cw.l
    [root@localhost exam2015]# gcc lex.yy.c -ll
    /usr/bin/ld: cannot find -ll
    collect2: error: ld returned 1 exit status.

    please help me to solve this problem.

  6. hello ankush,
    you can try following some commands which will help you to resolve problem:

    [exam2015@localhost ~]$ su
    Password:
    [root@localhost exam2015]# sudo yum update lex..

    if not solved then you may re-install lex package.

    Hope this will help you….

Comments are closed.