visual studio 2010 include directory paths

user1612986 picture user1612986 · Nov 13, 2012 · Viewed 10.4k times · Source

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.

Answer

Cheers and hth. - Alf picture Cheers and hth. - Alf · Nov 14, 2012

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.