Boost Library cannot get to work in C++, Include directories not working(Boost 库无法在 C++ 中工作,包含目录不起作用)
问题描述
我最近尝试在 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.0oostoost"
添加后我尝试编译:
#include <boostvariant.hpp>
在错误列表窗口中,我可以看到 E1696 - cannot open source file "boostvariant.hpp"
并且我无法像以前那样编译.
In Error List window, I can see E1696 - cannot open source file "boostvariant.hpp"
and I can't compile like before.
然后我尝试添加像 "C:Program Files (x86)Microsoft Visual Studio 14.0oostoost" 这样的反斜杠,仍然没有用.
Then I tried with adding a backslash like "C:Program Files (x86)Microsoft Visual Studio 14.0oostoost", 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.0oostoostvariant.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 - 无法打开源文件boost
或 E1696 - 无法打开源文件boost
All those errors are E1696 - cannot open source file "boost<libraryname.hpp>"
or E1696 - cannot open source file "boost<subdirs><some other files included in libraryname.hpp>"
所以,如果我从项目的头文件中删除 #include "C:Program Files (x86)Microsoft Visual Studio 14.0oostoostvariant.hpp"
行,所有错误突然消失,项目编译正常!现在没有任何错误!
So, if I remove the line #include "C:Program Files (x86)Microsoft Visual Studio 14.0oostoostvariant.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.
请帮我解决这个问题.
推荐答案
- 确保下载并安装正确的 boost 版本.可以将其安装在 Visual Studio 目录中,但不建议这样做.我建议您使用 here 中的软件包之一.假设您使用 Visual Studio 2017 并且您正在为 64 位开发,this 可能是适合您的正确软件包.
- 确保两者都做:将包含搜索路径和库搜索路径添加到您的 Visual Studio.
- 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.
包含搜索路径应指向 boost-installation 根目录(包含 Jamroot
文件和 boost
子目录的目录).库搜索路径应指向 boost 安装中正确的库子文件夹.这是以 lib64-msvc-**.*
(或 lib32-msvc-*
如果您正在开发 32 位)开头的子文件夹之一.
The include search path should point to the boost-installation root directory (the one that contains the Jamroot
file and a boost
subdirectory). The library search path should point to the correct library subfolder within the boost installation. This is one of the subfolders that start with lib64-msvc-**.*
(or lib32-msvc-*
if you're developing for 32bit).
上面二进制boost包的默认安装路径会安装到C:localoost_
.确保使用此安装目录中的路径并按照此处的说明进行操作.
The default install path of the binary boost package above will install it into C:localoost_<boost version>
. Make sure you use the paths from this installation directory and follow the instructions here.
例子:
包含搜索路径:C:localoost_1_64_0
库搜索路径:C:localoost_1_64_0lib64-msvc-14.1
这篇关于Boost 库无法在 C++ 中工作,包含目录不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Boost 库无法在 C++ 中工作,包含目录不起作用
基础教程推荐
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01