C 目标文件必须与相应的头文件同名吗?

发布于 2025-01-15 09:28:31 字数 170 浏览 4 评论 0原文

正如标题所问,目标文件是否必须与头文件具有相同的名称才能正确链接?

IE。我可以有一个头文件“foo.h”并将其命名为“bar.o”并且仍然可以正确链接吗?

在源代码中,我仍然需要编写 include "foo.h" 因此我推测链接器会拒绝它,因为两者不共享相同的名称。

As the title asks, do object files have to have the same name as the header file in order to be properly linked?

ie. could I have a header file 'foo.h' and call it 'bar.o' and still have it properly link?

In source code, I would still need to write include "foo.h" so I speculate that the linker will reject this since the two do not share the same name.

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

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

发布评论

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

评论(1

北笙凉宸 2025-01-22 09:28:31

没有任何内容表明特定的头文件与特定的目标文件相关联。

头文件通常只包含声明。它没有说明任何有关关联定义所在位置的信息。您可以有两个源文件,例如 main.c 和 foo.c,并且都使用名为 common.h 的头文件。编译时,您可以创建 main.o 和 foo.o 并将它们链接到“myprogram”中。

There is nothing that says a particular header file is associated with a particular object file.

A header file typically contains only declarations. It does not say anything regarding where the associated definitions reside. You could have two source files such as main.c and foo.c and have both use a header file called common.h. When you compile, you could then create main.o and foo.o and link them together into "myprogram".

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