C++指定标头包括代码中的目录
有没有办法在代码中指定包含目录,也许通过#pragma?
我的项目设置为“src/”和“include/”文件夹。我正在尝试在 Visual Studio 2010 中进行编译,但我不想在项目设置中进行设置。
是否有另一种方法可以允许它编译,而不必将包含指定为
#include ../include/ss.h
Is there a way to specify include directories in the code, perhaps via a #pragma?
I have my project setup as "src/" and "include/" folders. I am trying to compile in Visual Studio 2010, but I don't want to set it up in the project settings.
Is there another way to allow it to compile instead of having to specify the include as
#include ../include/ss.h
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
指定搜索目录的正确方法是使用编译器标志。在 Visual Studio 中,您可以通过使用项目设置或其编译器的
/I
命令行参数来完成此操作。The Correct(tm) way to specify search directories is with compiler flags. In Visual Studio you do this by playing with the project settings, or its compiler's
/I
commandline parameter.在 Visual Studio 中,您还可以通过选项/文件位置设置包含文件夹来定义它们。那么您就不需要在每个项目设置中重复它们。 (假设这就是您所追求的)。在源代码中定义绝对路径有点奇怪,您永远不会知道构建是从哪个文件夹/驱动器运行的。
In Visual studio, you can also define include folders by setting them via Options/File Locations. Then you don't need to repeat them in every project setting. (Assuming that's what you're after). It is a bit weird to define absolute paths in source code, you'll never know from which folder/drive a build is run.