- Mastering Embedded Linux Programming
- Chris Simmonds
- 543字
- 2021-07-30 09:44:58
What is a toolchain?
A toolchain is the set of tools that compiles source code into executables that can run on your target device, and includes a compiler, a linker, and run-time libraries. Initially, you need one to build the other three elements of an embedded Linux system: the bootloader, the kernel, and the root filesystem. It has to be able to compile code written in assembly, C, and C++ since these are the languages used in the base open source packages.
Usually, toolchains for Linux are based on components from the GNU project (and the associated LLVM project (be able to compile all the components needed for embedded Linux and so will become an alternative to GNU. There is a good description of how to use Clang for cross compilation at embedded Linux build system, the EmbToolkit (https://www.embtoolkit.org) fully supports both GNU and LLVM/Clang toolchains and various people are working on using Clang with Buildroot and the Yocto Project. I will cover embedded build systems in Chapter 6, Selecting a Build System. Meanwhile, this chapter focuses on the GNU toolchain as it is the only complete option at this time.
A standard GNU toolchain consists of three main components:
- Binutils: A set of binary utilities including the assembler, and the linker, ld. It is available at http://www.gnu.org/software/binutils/.
- GNU Compiler Collection (GCC): These are the compilers for C and other languages which, depending on the version of GCC, include C++, Objective-C, Objective-C++, Java, Fortran, Ada, and Go. They all use a common back-end which produces assembler code which is fed to the GNU assembler. It is available at http://gcc.gnu.org/.
- C library: A standardized API based on the POSIX specification which is the principle interface to the operating system kernel from applications. There are several C libraries to consider, see the following section.
As well as these, you will need a copy of the Linux kernel headers, which contain definitions and constants that are needed when accessing the kernel directly. Right now, you need them to be able to compile the C library, but you will also need them later when writing programs or compiling libraries that interact with particular Linux devices, for example to display graphics via the Linux frame buffer driver. This is not simply a question of making a copy of the header files in the include directory of your kernel source code. Those headers are intended for use in the kernel only and contain definitions that will cause conflicts if used in their raw state to compile regular Linux applications.
Instead, you will need to generate a set of sanitized kernel headers which I have illustrated in Chapter 5, Building a Root Filesystem.
It is not usually crucial whether the kernel headers are generated from the exact version of Linux you are going to be using or not. Since the kernel interfaces are always backwards-compatible, it is only necessary that the headers are from a kernel that is the same as or older than the one you are using on the target.
Most people would consider the GNU debugger, GDB, to be part of the toolchain as well, and it is usual that it is built at this point. I will talk about GDB in Chapter 12, Debugging with GDB.
- Learning Spring 5.0
- 深入淺出Java虛擬機:JVM原理與實戰
- PHP程序設計(慕課版)
- Java 9 Programming Blueprints
- 區塊鏈:以太坊DApp開發實戰
- Python Data Analysis(Second Edition)
- 人人都懂設計模式:從生活中領悟設計模式(Python實現)
- SQL基礎教程(視頻教學版)
- Haxe Game Development Essentials
- 全棧自動化測試實戰:基于TestNG、HttpClient、Selenium和Appium
- Java網絡編程核心技術詳解(視頻微課版)
- C++寶典
- Service Mesh實戰:基于Linkerd和Kubernetes的微服務實踐
- Mastering React
- Android群英傳