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??
Asked
Active
Viewed 2,371 times
2 Answers
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
-
Would you mind explaining it in a bit clear way – Nazeem Dec 08 '16 at 09:20
-
@Nazeem I think you are asking about shell script line, Here i mean if you have gcc compiler for 32 bit then you can compile your program with that like a cross compiler. Hope you got my point. – Sumit Gemini Dec 08 '16 at 09:25
-
https://gcc.gnu.org/ml/gcc-help/2010-09/msg00040.html this link could help you. – Sumit Gemini Dec 08 '16 at 09:28