Random thoughts shooting out of volatile mind
Tutorial: Cross compiling C application to i386 architecture
Recently I had to compile an C application for i386 architecture but I was running x86_64 Debian Wheezy. The libraries used for linking to create the final application where compiled for i386 arch and GCC was skipping them as it was not compatible one. I knew it is possible to cross compile using GCC but I was a noob to cross compilation. Searching in the internet took me to sites which suggests use of tool chains like binutils. But my program was too simple to undergo through all this. Finally I posted finally this question [1] on StackOverflow, and thanks to guys at Stackoverflow I got immidiate answer!

Well yeah as told its pretty easy for corss compiling for i386 architecture in gcc only thing is needed is you add -m32  in CFLAGS of your make file. You may also add -march=i386 to optimize it for i386 architecture. Yes you guessed it right this won't work simply you need to have entire i386 compatible libc and libc-dev files so if you are on Debian based system then use following command to install it.
sudo apt-get install ia32-libs ia32-libs-dev libc6-dev-i386
If you want to know about other distro's well you better refer your distribution documentation.

Yes this will also works in clang compiler.

[1] http://stackoverflow.com/questions/7219256/cross-compiling-a-c-application-using-gcc

Signing off
-- Vasudev
Posted by: copyninja on Thursday, 1 September 2011

blog comments powered by Disqus
Fork me on GitHub