copyninja
copyninja

Reputation: 1417

Cross compiling a C application using GCC

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

Upvotes: 1

Views: 2015

Answers (3)

paulsm4
paulsm4

Reputation: 121849

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

Upvotes: 2

Chris Dodd
Chris Dodd

Reputation: 126488

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).

Upvotes: 2

user47322
user47322

Reputation:

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

Upvotes: 1

Related Questions