编译器和链接器有什么区别? [英] What are the differences between a compiler and a linker?

查看:27
本文介绍了编译器和链接器有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What is the difference between a compiler and a linker in C?

推荐答案

编译器将用人类可读的编程语言编写的代码转换为处理器可以理解的机器代码表示.此步骤创建 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.

这篇关于编译器和链接器有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆