- Embedded Systems Architecture
- Daniele Lacamera
- 440字
- 2021-06-25 21:55:01
C compiler
The C compiler is a tool responsible for translating source code into machine code, which can be interpreted by a specific CPU. Each compiler can produce machine code for one environment only, as it translates the functions into machine-specific instructions, and it is configured to use the address model and the register layout of one specific architecture. The native compiler included in most GNU/Linux distributions is the GNU Compiler Collection, commonly known as GCC. The GCC is a free software compiler system, distributed under the GNU general public license since 1987, and since then it has been successfully used to build UNIX-like systems. The GCC included in the system can compile C code into applications and libraries capable of running on the same architecture as the one of the machine running the compiler.
The GCC compiler takes source code files as input, with the .c extension, and produces object files, with .o extensions, containing the functions and the initial values of the variables, translated from the input source code into machine instructions. The compiler can be configured to perform additional optimization steps at the end of the compilation, which are specific for the target platform, and insert debug data to facilitate debugging at a later stage. A minimalist command line used to compile a source file into an object using the host compiler only requires the -c option, instructing the GCC program to compile the sources into an object of the same name:
$ gcc -c hello.c
This statement will try to compile the C source contained in the hello.c file and transform it into machine-specific code, that is stored in the newly created hello.o file.
Compiling code for a specific target platform requires a set of tools designed for that purpose. Architecture-specific compilers exist, which provide compilers creating machine instructions for a specific target, different from the building machine. The process of generating code for a different target is called cross-compilation. The cross-compiler runs on a development machine, the host, to produce machine-specific code that can execute on the target. In the next section, a GCC-based toolchain is introduced with the purpose of creating the firmware for an embedded target. The syntax and the characteristics of the GCC compiler are described there.
The first step for building a program made of separate modules is to compile all the sources into object files, so that the components needed by the system are grouped and organized together in the final step, consisting of linking together all the required symbols and arranging the memory areas to prepare the final executable, which is done by another dedicated component in the toolchain.
- Linux系統(tǒng)文件安全實(shí)戰(zhàn)全攻略
- FreeRTOS實(shí)時(shí)內(nèi)核應(yīng)用指南
- 新手易學(xué):系統(tǒng)安裝與重裝
- 高性能Linux服務(wù)器構(gòu)建實(shí)戰(zhàn):系統(tǒng)安全、故障排查、自動化運(yùn)維與集群架構(gòu)
- Linux運(yùn)維最佳實(shí)踐
- 從實(shí)踐中學(xué)習(xí)Kali Linux無線網(wǎng)絡(luò)滲透測試
- RHCSARHCE 紅帽Linux認(rèn)證學(xué)習(xí)指南(第7版)EX200 & EX300
- Red Hat Enterprise Linux 6.4網(wǎng)絡(luò)操作系統(tǒng)詳解
- OpenHarmony開發(fā)與實(shí)踐:基于紅莓RK2206開發(fā)板
- CSS揭秘
- Java EE 8 High Performance
- 電腦辦公(Windows 7+Office 2016)入門與提高
- Responsive Web Design with AngularJS
- 微信小程序項(xiàng)目開發(fā)實(shí)戰(zhàn):用WePY、mpvue、Taro打造高效的小程序
- 跟老男孩學(xué)Linux運(yùn)維:Web集群實(shí)戰(zhàn)