1
votes

I would like to build an application for i386 architecture but currently I'm running x86_64 OS and shared libraries which I use to link to generate application binaries are built for i386 architecture. If I run file command on shared libraries I use I get following output

ELF 32-bit LSB shared object, Intel 80386, version 1 (S│Size: 13064788 SV), dynamically linked, not stripped 

But gcc skips this shared library saying it as incompatible one. So I was just wondering is there any option with which I can tell GCC to compile for i386 architecture rather than for my native machine architecture?

Yes I've gone through many cross compilation questions on this forums but I didn't fully understand the funda as I'm new to cross compilation stuffs. Does cross compilation requires me to have a gcc which is built for same architecture as the architecture for which I'm trying to compile? Is use of tool chains like binutils is mandatory for cross compilation?

I'm using a simple handwritten make file and not using any tool specific tool chains.

Thanks in Advance

3

3 Answers

2
votes

The -m32 option tells the compiler to generate 32-bit code instead of 64 bit. You might also want -march=i386 if you specifically want 80386 code (and optimization).

2
votes

Actually, you might be able to get away with simply specifying "-m32" on your gcc build command. Try it :)

If you get link errors, then trying installing the 32-bit C runtime libraries; then retry your "gcc -m32" build:

sudo apt-get install ia32-libs
1
votes

GCC supports the -m32 flag which makes it compile for a 32 bit platform.