Components of the C compilation system

The C compilation system consists of a preprocessor, compiler, assembler, and link editor. The cc command invokes each of these components automatically unless you use command line options to specify otherwise. An executable C program is created by exposing the source code to these components via the cc command.

C preprocessor

The preprocessor component of the compiler reads lines in your source files that direct it to replace a name with a token string (#define), perhaps conditionally (#if, for example). It also accepts directives in your source files to include the contents of a named file in your program (#include). Included header files for the most part consist of #define directives and declarations of external symbols, definitions and declarations that you want to make available to more than one source file. See ``Libraries and header files'' for details.

C compiler

The compiler proper translates the C language code in your source files, which now contain the preprocessed contents of any included header files, into assembly language code.

C assembler

The assembler translates the assembly language code into the machine instructions of the computer your program is to run on. As indicated in ``Introduction to programming in standard C and C++'', these instructions are stored in object files that correspond to each of your source files. Each object file contains a binary representation of the C language code in the corresponding source file. Object files are made up of sections, of which there are usually at least two. The text section consists mainly of program instructions. Text sections normally have read and execute, but not write, permissions. Data sections normally have read, write, and execute permissions. See ``Object files'' for details of the object file format.

C linker

The link editor links these object files with each other and with any library functions that you have called in your program. When it links with the library functions depends on the link editing model you have chosen.

  • archive, or statically linked library, is a collection of object files each of which contains the code for a function or a group of related functions in the library. When you use a library function in your program, and specify a static linking option on the cc command line, a copy of the object file that contains the function is incorporated in your executable at link time. 
  • A shared object, or dynamically linked library, is a single object file that contains the code for every function in the library. When you call a library function in your program, and specify a dynamic linking option on the cc command line, the entire contents of the shared object are mapped into the virtual address space of your process at run time. As its name implies, a shared object contains code that can be used simultaneously by different programs at run time.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值