我有一个 Visual Studio 解决方案 myvs.sln ,路径如下:c:\dir1\dir2\dir3\myvs\myvs\myvs.sln
。我安装了 boost 版本 xxxc:\dir1\dir2\dir3\boostxxx\
.
我在项目->属性->c/c++->常规中:../..;../../boostxxx
。在 boost 库中,包含文件具有以下语法:#include <boost/smart_ptr/shared_ptr>
.
我的代码文件myfile.h
驻留在c:\dir1\dir2\dir3\yy1\myfile.h
。在 myfile.h 中,我将 boost 库包含为:#include <boost/shared_ptr.hpp>
。我收到一条错误消息:c:\dir1\dir2\dir3\yyy1/myfile.h fatal error C1083 cannot open include file boost/shared_ptr.hpp
.
问题是我应该做什么来纠正这个问题?
我还注意到编译器抛出的错误输出在 dir3 之前有“\”,然后更改为“/”。
我很可能不明白相对路径是如何工作的。另请注意,我只想引用相对路径而不是绝对路径。有人可以帮忙吗?我在windows平台上使用c++ Visual Studio 2010。
Relative paths in the search paths refer to the directory of the file with the #include
directive the current directory of the compiler, some simple testing now shows.
"..\.." is going up two levels from your header file the current directory of the compiler instead of from your project directory.
要解决此问题,请在 Visual Studio 项目目录中显式启动包含路径,如下所示(字面意思):
$(项目目录)..\..;$(项目目录)..\..\BoostXXX
关于正斜杠与反斜杠,请在 C++ 代码中使用正斜杠#include
指令,因为这是最便携的。
当您引用 Windows 文件系统时,例如在包含路径的设置中,请使用正斜杠或反斜杠(但我更喜欢使用反斜杠,以便具有单一约定)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)