LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-04-2010, 12:00 PM   #1
nkoplm
Member
 
Registered: May 2005
Distribution: Fedora
Posts: 92

Rep: Reputation: 15
Basic cross compiling tutorial?


Hello,

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)?
 
Old 02-04-2010, 05:00 PM   #2
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Hey,

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 of all, here's a basic tutorial for gcc on Linux: http://linux.bytesex.org/cross-compiler.html

Generally, you need the following things:
  • cross compiler, you could build gcc as a cross-compiler for any support platform (for example, --host=<x86>, but --target=<ia64>)
  • binutils of your target platform (linker, assembler), because you will have to finally link the app on your system
  • header files of your target system
  • libraries of your target system, because the linker must be able to access static and shared libraries for linking the application

That's just a basic skeleton, but hopefully it gives you some starting points ...

- Andi -
 
Old 02-05-2010, 09:33 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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

Last edited by theNbomr; 02-05-2010 at 09:36 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cross-compiling v/s cross-building kushalkoolwal Programming 3 05-13-2009 05:49 AM
Need some basic tutorial for Knoppix. fredy_ricky Linux - Newbie 2 09-29-2008 04:23 PM
Basic Networking With Windows Tutorial Boffy Linux - General 1 08-10-2004 06:39 AM
In need of VERY BASIC Mandrake Linux 9 Tutorial... joeblk Mandriva 1 05-17-2004 04:22 AM
In need of BASIC Mandrake Linux 9 Tutorial... joeblk Linux - Newbie 1 05-17-2004 03:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration