Boost库无法在C ++中工作,包含目录不起作用 [英] Boost Library cannot get to work in C++, Include directories not working
问题描述
我最近尝试在C ++ 14中安装Boost库,并添加了它的包含路径,如:
I recently tried to install boost libraries in C++ 14, and I added it's include paths like:
解决方案资源管理器>项目名称>属性页> VC ++目录>"C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ boost \ boost"
添加此代码后,我尝试进行编译:
I tried to compile after adding this:
#include <boost\variant.hpp>
在错误列表"窗口中,我可以看到E1696 - cannot open source file "boost\variant.hpp"
,并且无法像以前那样进行编译.
In Error List window, I can see E1696 - cannot open source file "boost\variant.hpp"
and I can't compile like before.
然后,我尝试添加反斜杠,例如"C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ boost \ boost \" ,仍然无法正常工作.
Then I tried with adding a backslash like "C:\Program Files (x86)\Microsoft Visual Studio 14.0\boost\boost\", still didn't work.
我还阅读了此发布并明确指定它的目录,但甚至不起作用.
I also read this post and explicitly specified it's directory, but even didn't work.
再次,我阅读了这篇帖子,其内容完全相同给定答案(因为我已经多次构建项目),但仍然没有成功.
Again, I read this post and did exactly same what is in given answer (as I already built project several times) , but still no success.
但是,如果我包括一个像这样的图书馆:
However, if I include a library like:
#include "C:\Program Files (x86)\Microsoft Visual Studio 14.0\boost\boost\variant.hpp"
现在编译器可以识别它,但是现在我可以在错误列表"窗口中看到100多个错误,这些错误是指向boost库的头文件的,而不是包含在我的包含variant.hpp
的项目文件中.
Now compiler recognizes it, but now I can see more than 100 errors in Error List window, those errors are pointed to header files of boost libraries, not in my project file which has variant.hpp
included.
所有这些错误是E1696 - cannot open source file "boost\<libraryname.hpp>"
或E1696 - cannot open source file "boost\<subdirs>\<some other files included in libraryname.hpp>"
因此,如果我从项目的头文件中删除行#include "C:\Program Files (x86)\Microsoft Visual Studio 14.0\boost\boost\variant.hpp"
,则所有错误突然消失并且项目编译正常!现在没有任何错误!
So, if I remove the line #include "C:\Program Files (x86)\Microsoft Visual Studio 14.0\boost\boost\variant.hpp"
from my project's header file, all errors disappear suddenly and project compiles fine! no any single error now!
无论如何我都希望Boost能够工作,所以我可以在项目中使用它,但是我不能手动编辑所有这些头文件并将<boost\...
更改为原始位置.
I want boost to work anyway, so I can use it in projects, but I can't manually edit all those header files and change <boost\...
to original locations.
请帮助我摆脱这个问题.
Please help me to get rid of this issue.
推荐答案
- 请确保您下载并安装了正确的Boost版本.可以在Visual Studio目录中安装它,但不建议这样做.我建议您使用此处中的软件包之一.假设您使用Visual Studio 2017 和,并且正在为64位开发
- make sure you download and install the correct boost version. Installing it in the visual studio directories is possible, but not advised. I suggest you use one of the packages from here. Assuming you use visual studio 2017 and you are developing for 64bit, this could perhaps be the correct package for you.
- make sure you do both: adding the include search path and the library search path to your visual studio.
include搜索路径应指向boost-installation根目录(包含
Jamroot
文件和boost
子目录的目录).库搜索路径应指向boost安装中正确的库子文件夹.这是从lib64-msvc-**.*
开头的子文件夹之一(如果您正在开发32bit,则为lib32-msvc-*
).The include search path should point to the boost-installation root directory (the one that contains the
Jamroot
file and aboost
subdirectory). The library search path should point to the correct library subfolder within the boost installation. This is one of the subfolders that start withlib64-msvc-**.*
(orlib32-msvc-*
if you're developing for 32bit).上面的二进制boost软件包的默认安装路径会将其安装到
C:\local\boost_<boost version>
中.确保使用此安装目录中的路径,并按照说明此处进行操作.The default install path of the binary boost package above will install it into
C:\local\boost_<boost version>
. Make sure you use the paths from this installation directory and follow the instructions here.示例:
包含搜索路径:
C:\local\boost_1_64_0
库搜索路径:
C:\local\boost_1_64_0\lib64-msvc-14.1
这篇关于Boost库无法在C ++中工作,包含目录不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!