且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

编译器和链接器有什么区别?

更新时间:2023-11-09 11:29:52

编译器将用人类可读的编程语言编写的代码转换为处理器可以理解的机器代码表示.此步骤创建 object 文件.

The compiler converts code written in a human-readable programming language into a machine code representation which is understood by your processor. This step creates object files.

编译器完成此步骤后,还需要另一个步骤来创建可以调用和运行的工作可执行文件,即关联您的编译代码需要调用才能工作的函数调用(例如).例如,您的代码可以调用 sprintf,它是 C 标准库中的例程.您的代码与 sprintf 提供的实际服务没有任何关系,它只是报告必须调用它,但实际代码位于公共 C 库中的某个位置.要执行此(以及许多其他)链接,必须调用 链接器.链接后,就获得了可以运行的实际可执行文件.

Once this step is done by the compiler, another step is needed to create a working executable that can be invoked and run, that is, associate the function calls (for example) that your compiled code needs to invoke in order to work. For example, your code could call sprintf, which is a routine in the C standard library. Your code has nothing that does the actual service provided by sprintf, it just reports that it must be called, but the actual code resides somewhere in the common C library. To perform this (and many others) linkages, the linker must be invoked. After linking, you obtain the actual executable that can run.