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

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

问题描述

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

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

推荐答案

可读的编程语言转换为处理器理解的机器码表示。此步骤创建对象文件。

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天全站免登陆