If you want to cross compile a progam, the steps don't obviously differ from the ones needed to compile it for your personal computer. But there are some things to keep in mind for avoiding getting tired or crazy.
First, the platform which runs the cross compiler is called host. The target platform, for which the program is compiled, is called target (really? :-).
The program, you've compiled doesn't run - on your host, unless you've got a simulator or you've loaded it to the target. All the programs in this article are loaded in the target because it doesn't exist a simulator for Linux for the SEGA Dreamcast unfortunately.
The following problems while cross compiling appear frequently during the writing process of this article (ordered by difficulty):
A generic solution would be customizing the Makefile by courtesy of an environment variable:
... christian@helicon:~$ export CC=/usr/local/foo/cc christian@helicon:~$ make ...
Another possibility would be the modification of the Makefile and the change of the entry for the CC= variable.
The examples above don't refer only to the C - compiler but also to ar, an archiver, to ranlib, an indexer for archives or to other programs used to compile the source.
This problem has normally two reasons: The Makefile searches in the improper directories or the library - and header - files don't exist. The first problem can be solved as mentioned above: You modify your environment or the Makefile of the source - package. The latter is solved by installing the missing library.
This problem is sometimes easy to solve, but sometimes you have to cheat and bluff make that you have a correctly constructed Makefile.
These packages often include a script called configure. This script tries to build a Makefile using lots of templates (config.in, Makefile.in, ...) for getting an optimal Makefile which is suitable for your system. Occasionally, you can use the configure - script for building a cross compiling - Makefile, but often you will run into problems due to missing test programs because these test programs produced by the configure - script can't run on the host platform.
Sometimes, there's a trick to run configure
for the host platform
and edit the resultant Makefile for the target platform.
This never looks good. The problem can be solved easily or costs nights to be solved. Often, it's a missing directory or program that can be added easily. But sometimes, the compiler complains about code that can't be compiled for the target you wish. This is up to assembly code that won't run on or can't be interpreted by the target platform. The latter is hard to solve because you have to look for a workaround, a switch or an environment variable that prohibits the use of native assembly code. The README included in the source - package would be a good start.
This problem is very hard to solve. Do you check every output of the compiling process? Is the program executable on the target platform? Is it a problem of rights (chmod)? Are some device nodes missed? Are some configuration files missed? You may solve the problems by using gdb, the GNU debugger.
As you see, cross compiling is nothing you do in five minutes, but it's something very interesting and challenging. The programs described in this article come along with a patch that helps you to compile the source for the sample target SEGA Dreamcast and comprehend the modifications I've got to perform.