官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 西盟| 鲜城| 左云县| 渑池县| 潮安县| 桐柏县| 集贤县| 佳木斯市| 阿拉善右旗| 汤原县| 甘泉县| 齐齐哈尔市| 隆德县| 怀远县| 岚皋县| 迁西县| 中江县| 寿阳县| 思茅市| 丽江市| 济宁市| 准格尔旗| 三台县| 潜江市| 天峨县| 昭觉县| 四川省| 泾川县| 化隆| 宁夏| 神木县| 锡林浩特市| 峨眉山市| 沙雅县| 八宿县| 石棉县| 湄潭县| 胶州市| 古交市| 织金县| 宜川县|