visual studio 2010 include directory paths

南笙酒味 提交于 2019-12-23 13:09:23

问题


I have a visual studio solution myvs.sln with the following path: c:\dir1\dir2\dir3\myvs\myvs\myvs.sln. I have boost version xxx installed in c:\dir1\dir2\dir3\boostxxx\.

I have in the project->properties->c/c++->general: ../..;../../boostxxx. Inside boost libraries the include files have the following syntax: #include <boost/smart_ptr/shared_ptr>.

My code file myfile.h resides in c:\dir1\dir2\dir3\yy1\myfile.h. In myfile.h I include boost libraries as: #include <boost/shared_ptr.hpp>. I am getting a error which says: c:\dir1\dir2\dir3\yyy1/myfile.h fatal error C1083 cannot open include file boost/shared_ptr.hpp.

The question is what should I do to correct this?

I also notice that the error output the compiler throws has "\" upto dir3 and then changes to "/".

Most probably I do not understand how the relative path is working. Also note that I want to refer to only relative path not absolute paths. Can someone please help? I am in windows platform using c++ visual studio 2010.


回答1:


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.

To fix this, explicitly start your include paths in your Visual Studio project directory, as follows (literally):

$(ProjectDir)..\..;$(ProjectDir)..\..\BoostXXX

Regarding forward versus backward slash, use forward slash in your C++ code's #include directives, because that's most portable.

Use either forward or backward slash (but I prefer backwards slash so as to have a single convention) where you're referring to the Windows file system, such as in the setup of include paths.



来源:https://stackoverflow.com/questions/13367999/visual-studio-2010-include-directory-paths

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!