This is part of a series on using Linux for embedded systems. For a list of other articles in this series, check out the introductory post.

The Linux Foundation_ sponsored this post._

John Bonesio

John is a Linux Instructor at The Linux Foundation.

When working with embedded Linux systems, one of the first things you need is a cross compiler toolchain.

For the uninitiated, cross compiler tools are a set of tools (compiler, linker, assembler, etc.) that produce code in your compiled programs for a CPU instruction set different from your host machine’s CPU. For example, if you have a cross toolchain for ARM, you would compile your programs on your x86 laptop or desktop computer, and these programs would run on your embedded ARM system rather than on your laptop/desktop.

This article will refer to a lot of terms, such as kernels, bootloaders, root filesystems, and more. If these terms are unfamiliar to you, you can review previous articles in this series: Part 1Part 2.

Using Existing Tools

There exist prebuilt cross embedded tools for ARM, PowerPC, MIPS, and more. If you are using a Debian based Linux distribution, such as Ubuntu, it’s likely you can just install them using Debian’s package system. For example:

sudo apt-get install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi

Other Linux distributions may also provide prebuilt compiler tools. These prebuilt tools often support C, C++, Objective C, Fortran, and more. And there are tools that support various hardware features in your embedded platform, such as the floating-point unit.

Sponsor Note

sponsor logoThe Linux Foundation is dedicated to building sustainable ecosystems around open source projects to accelerate technology development and commercial adoption. Founded in 2000, the foundation supports communities through infrastructure, services, events and training.

Using these prebuilt tools is probably the easiest way to get started building various software components of your embedded Linux system.

Building Your Own Tools

If you need more control, such as optimizing for size or making use of even more control over your processor features, you can build the compiler toolchain yourself.

Building the cross-compiler toolchain is pretty tricky. To build it correctly, it needs to be built three times to bootstrap the whole process — building a simple compiler to build libraries, then rebuilding it to use the libraries, etc. Most people don’t build cross-compiler tools by hand; instead, they use other tools to build them. There are a few tools available to build your own cross-compiler toolchain. Here are just a few of the more commonly used ones.

Crosstool-NG

Crosstool-NG is a tool that builds cross toolchains. It will also build the standard libraries for your programs to link. You can find more information about crosstool-NG here.

Buildroot

Buildroot’s goal is to build an entire root filesystem — all the programs that go into /bin, /sbin, etc. As part of this process, Buildroot will also build the cross toolchain. Buildroot will build the cross toolchain, shared libraries and all the binary programs for the root filesystem, and will create a directory hierarchy of the root filesystem. Buildroot also optionally lets you build the kernel and the bootloader.

One advantage of Buildroot over crosstool-NG is that it will include all the shared libraries in the root filesystem — libraries that are needed if using dynamic linking. With crosstool-NG, these would need to be added to the root filesystem by some other process. You can find more information about Buildroot here.

#development #linux #tools #contributed #sponsored

Compiler Tools for Embedded Linux Systems
1.15 GEEK