链接多个 .h 文件

发布于 2024-12-23 18:24:39 字数 99 浏览 4 评论 0原文

如何在终端中使用 g++ 在 Linux 终端的 .cpp 文件中编译多个 .h 文件。我尝试用一​​个 .cpp 文件编译两个不同的 .h 文件,但没有成功。我怎样才能让它发挥作用?

How do I compile mutlitple .h files within a .cpp file in linux terminal using g++ in the terminal. I tried compiling two different .h files with one .cpp file and it didn't work. How can I get this to work?

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

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

发布评论

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

评论(4

层林尽染 2024-12-30 18:24:39
#include "header.h"
#include "other_header.h"

只需#include它们。我想这就是你所说的链接的意思。

#include "header.h"
#include "other_header.h"

Just #include them. I think that's what you mean by link.

魂归处 2024-12-30 18:24:39

我不知道你所说的“链接”是什么意思。

#include .cpp 文件中的.h 文件。

I don't know what you mean by "link".

You #include the .h files from the .cpp file.

少跟Wǒ拽 2024-12-30 18:24:39

您的 .cpp 文件中的两个 .h 文件必须有单独的 #include "path-to-file.h"

You would have to have seperate #include "path-to-file.h" for both .h files in your .cpp file.

清君侧 2024-12-30 18:24:39

您是否偶然使用某种预编译头?如果是这样,您可能需要更新预编译头以包含更改。我只拥有使用带有预编译头的 Microsoft Visual Studio 的经验,因此我不确定使用 g++ 的确切方式。

你的问题很不清楚,你的术语表明你并没有真正理解这个系统。虽然这本身并不是问题(我们都曾经是初学者),但您需要格外小心,真正关注那些试图帮助您的人。在我看来,发布“如何回答”是对那些试图提供帮助的人的侮辱;侮辱是你告诉他们回答问题的要求,但你一开始并没有明确你真正要求的是什么。

Are you by chance using precompiled headers of some sort? If so, you may need to update the precompiled headers to include changes. I've only had experience with using Microsoft's Visual Studio with precompiled headers, so I'm not sure of the exact way it's done with g++.

Your question is very unclear, and your terminology shows that you don't really understand the system very well. While that's not a problem in and of itself (we were all once beginners), you need to be extra careful to really pay attention to people that are trying to help you. Posting that "How to Answer" was, in my opinion, an insult to those trying to help; the insult is that you are telling them to answer what the question is asking for, but you are not making it clear what you are actually asking for in the first place.

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