ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have written a program that I would like to cross compile for x86 and x86_64 architectures. I have tried google and the search function here to no success, most information I find is too specific (instructions for a specific program), or dealing with cross compiling for windows on linux.
Does anyone know of a tutorial dealing with straight making a 32 bit binary on a 64 bit processor (both are intel)?
that what you're talking about is not really cross-compiling, because the x86_64 instruction set is just an extension to the x86 instruction set so that I would assume that most compilers for x86_64 also allow you to compile 32-bit code (at least gcc does by using the -m32 flag).
Cross compiling really means that you build your executable e.g. on Linux/x86, but the application will finally be executed on a PowerPC.
First, you need a cross compiler (cross toolchain, to be more accurate) that runs on your build host, and creates object code for the target host. After that, it can be as simple as having your makefile point at the cross compiler when performing the build of your application.
To build a cross toolchain on your build host, you can use a tool such as crosstool-ng.
Code:
theNbomr@myhost:~/junk$ touch helloWorld.c
theNbomr@myhost:~/junk$ make CC=~/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc helloWorld
/home/theNbomr/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc helloWorld.c -o helloWorld
theNbomr@myhost:~/junk$ file helloWorld
helloWorld: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.31, not stripped
This example uses a cross toolchain targeting a ARM processor, just because I had that at hand, and because the resulting object code is more distinct than simply a variant of another x86 CPU target object code.
--- rod
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.