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

发布于 2024-09-26 05:09:52 字数 26 浏览 0 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最丧也最甜 2024-10-03 05:09:52

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

编译器完成此步骤后,还需要执行另一个步骤来创建可以调用和运行的工作可执行文件,即关联编译后的代码需要调用才能工作的函数调用(例如)。例如,您的代码可以调用 sprintf,它是 C 标准库中的例程。您的代码没有执行 sprintf 提供的实际服务,它只是报告必须调用它,但实际代码驻留在公共 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.

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.

白馒头 2024-10-03 05:09:52

编译器从源代码生成目标代码文件(机器语言)。

链接器将这些目标代码文件组合成可执行文件。

许多 IDE 会连续调用它们,因此您永远不会真正看到链接器在工作。某些语言/编译器没有不同的链接器,链接是由编译器作为其工作的一部分完成的。

A compiler generates object code files (machine language) from source code.

A linker combines these object code files into an executable.

Many IDEs invoke them in succession, so you never actually see the linker at work. Some languages/compilers do not have a distinct linker and linking is done by the compiler as part of its work.

燃情 2024-10-03 05:09:52

简单来说 ->每当“.obj”文件需要与其库函数链接时,链接器就会起作用,因为编译器不理解什么是(scanf或printf..etc),编译器只是转换“.c”在不了解我们使用的库函数的情况下,如果没有错误,则将文件复制到“.obj”文件。因此,为了将“obj”文件生成“exe”(可执行文件),我们需要链接器,因为它使编译器能够理解库函数

In Simple words -> Linker comes into act whenever a '.obj' file needs to be linked with its library functions as compiler doesn't understand what is (scanf or printf..etc) , compiler just converts '.c' file to '.obj' file if there's no error without understanding library functions we used. So To make 'obj' file to 'exe'(executable file) we need linker because it makes compiler understand of library functions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文