GCC Cross-Compiler on Debian Linux

From OSDev Wiki
Jump to: navigation, search

For some reason the repositories are currently broken. I'm trying to figure out why. JackScott 05:42, 20 July 2010 (UTC)

By far the easiest way to obtain a GCC Cross-Compiler, if you are running Debian GNU/Linux or Ubuntu Linux, is to install one of the binary packages built by bored forum members. Getting set up is fairly easy, and once done, you will get automatically updated to newer versions of GCC soon after they come out. The compiler set includes support for C and C++, as well as libgcc.

The package and repository system is designed so that multiple cross-compiler targets (for instance, both i586-elf and powerpc-elf) can be installed on a system without any clashes.

Note to Debian users: the following code examples assume you have sudo installed on your system.

Contents

Prerequisites

Firstly, you'll need to have an up to date Debian or Ubuntu system. If you are using another operating system, these cross compilers won't work.

Secondly, you need to understand that these packages have no warranty. While several users are using them on production servers, it is NOT RECOMMENDED. Any damage (including data loss) caused is not the fault of any of the package maintainers, or the mirror owners.

Setting Up

Step 1: Add an Archive to /etc/apt/sources.list

Run the following from the command line:

sudo nano /etc/apt/sources.list

And then the following line (anywhere in the file will do):

deb http://www.tucs.org.au/~jscott4/debian/ stable main    #Primary Mirror. Hosted by University of Tasmania.

After you've added the line, use Ctrl+X to exit, remembering to save the file.


Step 3: Update the Package Lists

Run the following from the command line:

sudo apt-get update

Installing A Cross-Compiler

Step 1: Checking the Package You Want Exists

Unfortunately, packages don't exist for every single target architecture (the machine you want to compile for) and every host architecture (the machine you are doing the compiling on). You can check the packages that have been built in the table below.

The target architecture names running across the top of the table should be substituted for $TARGET in Step 2. Note that x86_64-elf has been renamed x86-64-elf for the purposes of installing the packages. The host architectures run down the table.

i586-elf x86-64-elf powerpc-elf sparc-elf ia64-elf
i386 Yes Yes Yes Yes Yes
AMD64 Yes Yes Yes Yes Yes

Step 2: Installing the Package

Run the following from the command line:

sudo apt-get install osdev-crosscompiler-$TARGET

Replace $TARGET with the name of a target architecture, as described in step 1. For instance, for a "standard" i586-elf cross-compiler for compiling the Bare Bones:

sudo apt-get install osdev-crosscompiler-i586-elf

Using Your Cross-Compiler

The package, upon installation, will set up your $PATH variable so that upon your next login you have immediate access to the cross compilers. To use one of the tools (for example, GCC), run like the following:

x86_64-elf-gcc -c myFile.c -o myFile.o

This same pattern (TARGET-gcc, TARGET-ld, etc) is the same for all tools in the GCC and Binutils collection.

The Internals: How It All Works

TODO

The short story: voodoo magic.

Need Help?

Ask a question in the forum. Alternatively, contact the following people for support:

  • JackScott - Package Maintainer, Main Server Owner

Want To Help?

TODO

See Also

Articles

External Links

Personal tools
Namespaces
Variants
Actions
Navigation
About
Toolbox