编译gcc .c文件与将.c文件制成.o文件并链接和组合相比有何区别? [英] What is the difference compiling gcc .c file in comparison to making a .c file into an .o file and linking and assembling?

查看:265
本文介绍了编译gcc .c文件与将.c文件制成.o文件并链接和组合相比有何区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始参与GCC。

I have just started getting involved with GCC.

假设我们有一个由vim labaled helloworld.c编写的文本文件

Lets say we have a text file written by vim labaled helloworld.c

为什么SWIM不是我)与 gcc -c helloworld.c 相比,使用

Why would SWIM (someone who isn't me) compile it with

gcc helloworld.c 然后 gcc -o helloWorld helloworld.o

推荐答案

对于一个文件,没有用。
但是如果你编译一个更大的项目,你可能不想重新编译所有文件,如果你只更改一个。

For one single file, there is no use. But if you compile a larger project, you may not want to recompile all files, if you only changed one for instance. And thus, gain compile time.

使用中间 .o 文件只能重新编译需要重新编译的内容,并链接最终的二进制文件与所有这些对象文件。

Using intermediate .o files lets you only recompile what needs to be recompiled, and link the final binary with all those objects files.

另一个用例是,如果你想使用自定义链接脚本,例如选择你的部分或代码的位置。然后你需要从 .o 文件中获取实际的代码。

Another usecase is if you want to use a custom link script, for instance to choose the location of your sections or code. Then you need to get the actual code from .o files.

这篇关于编译gcc .c文件与将.c文件制成.o文件并链接和组合相比有何区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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