1

I want to create binary executable of my source code to run on 32 bit gcc machine. But I have 64 bit gcc installed. Is there any way to create a binary executable for 32 bit gcc machines from my 64 bit gcc??

sepp2k
  • 363,768
  • 54
  • 674
  • 675
Nazeem
  • 59
  • 11

2 Answers2

3

My machine is ELF 64-bit LSB by default if u compile it will produce you 64 bit executable.

 gcc  hello.c -o hello

use file to check it

 hello: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=9f8fa8ac13fc03672306da1d5d4ee6671114eb11, not stripped

Use flag -m32 then you forcing your compiler for 32 bit

  gcc -m32 hello.c -o hello

 file hello
 hello : ELF 32-bit LSB  executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=c72216023939b2832467c624850f164d1857e645, not stripped

If you looking for cross-compiling This might help u How to determine host value for configure when using cross compiler

Community
  • 1
  • 1
vinay hunachyal
  • 3,781
  • 2
  • 20
  • 31
1

You need to make GCC use the -m32 flag.

You could try writing a simple shell script to your $PATH and call it gcc (make sure you don't overwrite the original gcc, and make sure the new script comes earlier in $PATH, and that it uses the full path to GCC.

compile your binary like -:

/bin/gcc -m32 "source file"
Sumit Gemini
  • 1,836
  • 1
  • 15
  • 19