简体   繁体   English

C ++指定标题包含代码中的目录

[英]C++ Specify Headers Include Directory in Code

Is there a way to specify include directories in the code, perhaps via a #pragma? 有没有办法在代码中指定包含目录,也许是通过#pragma?

I have my project setup as "src/" and "include/" folders. 我的项目设置为“src /”和“include /”文件夹。 I am trying to compile in Visual Studio 2010, but I don't want to set it up in the project settings. 我想在Visual Studio 2010中编译,但我不想在项目设置中进行设置。

Is there another way to allow it to compile instead of having to specify the include as 是否有另一种方法允许它编译而不必指定include as

#include ../include/ss.h

The Correct(tm) way to specify search directories is with compiler flags. 指定搜索目录的Correct(tm)方法是使用编译器标志。 In Visual Studio you do this by playing with the project settings, or its compiler's /I commandline parameter. 在Visual Studio中,您可以通过使用项目设置或其编译器的/I命令行参数来执行此操作。

In Visual studio, you can also define include folders by setting them via Options/File Locations. 在Visual Studio中,您还可以通过“选项/文件位置”设置包含文件夹。 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. 在源代码中定义绝对路径有点奇怪,你永远不会知道构建运行的文件夹/驱动器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM