如何将某些内容放入我的“包含路径”中?

发布于 2024-10-03 14:07:09 字数 219 浏览 1 评论 0原文

我将所有项目包含文件放在特定目录中(在我的项目目录中称为 include)。当我将它们包含在 cpp 文件中时,我需要

#include "include/somefile.h"

如何制作才能做到这一点

#include <somefile.h>

I have all my project include files in a specific dir (called include, in my project dir). When I include them in a cpp file, I need to

#include "include/somefile.h"

How can I make it so that I can do

#include <somefile.h>

?

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

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

发布评论

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

评论(2

梦罢 2024-10-10 14:07:09

使用编译器的 -I 标志。喜欢:

~$ c++ -Wall -Werror -pedantic -I/home/user/include -c source_file.cpp

Use the -I flag of the compiler. Like:

~$ c++ -Wall -Werror -pedantic -I/home/user/include -c source_file.cpp
蓝颜夕 2024-10-10 14:07:09

使用双引号包含本地工作目录中的查找,而包含在尖括号中的包含告诉链接器/编译器在标准位置查找,例如 /usr/bin/ (在 *nix 平台上)。您可以使用 -I 编译器指令告诉它查看其他位置(至少对于 gcc/g++,像 Visual Studio 这样的 IDE 有自己的机制)。

Using double quotes to include looks within the local working directory, while includes wrapped in angle brackets tell the linker/compiler to look in standard locations such as /usr/bin/ (on *nix platforms). You can tell it to look other places with the -I compiler directive (with gcc/g++ at least, IDEs like Visual Studio have their own mechanisms).

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