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

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.

主站蜘蛛池模板: 临颍县| 嘉兴市| 全南县| 新蔡县| 中山市| 湟源县| 开阳县| 鹿泉市| 呼伦贝尔市| 名山县| 黄龙县| 利津县| 肇州县| 阳原县| 积石山| 青阳县| 文安县| 宝鸡市| 吉林省| 靖宇县| 汉阴县| 曲阜市| 伊金霍洛旗| 错那县| 侯马市| 阳原县| 西盟| 罗山县| 垫江县| 呼图壁县| 溧阳市| 汕尾市| 岫岩| 获嘉县| 绥阳县| 娄烦县| 北宁市| 竹溪县| 阳信县| 措勤县| 介休市|