[英]How do I include Boost libraries?
I'm trying to incorporate the Boost libraries into my program, specifically lexical_cast
and geometry
. 我正在尝试将Boost库合并到我的程序中,特别是lexical_cast
和geometry
。 I include them using #include"boost/boost/geometry.hpp"
and #include"boost/boost/lexical_cast/lexical_cast_old.hpp"
. 我使用#include"boost/boost/geometry.hpp"
和#include"boost/boost/lexical_cast/lexical_cast_old.hpp"
。
When I run the code I get the fatal error "Cannot open include file: 'boost/geometry/geometry.hpp': No such file or directory" which leads me to another .hpp file in the Boost library which includes another library, but uses #include<...>
instead of #include"..."
. 当我运行代码时,我得到了致命的错误“无法打开包含文件:'boost / geometry / geometry.hpp':没有这样的文件或目录”这导致我在包含另一个库的Boost库中的另一个.hpp文件,但是使用#include<...>
而不是#include"..."
。
When I replace it for "..."
the error for this one goes, but it is replaced with the next library included using #include<...>
instead of #include"..."
. 当我替换它为"..."
这个错误就会消失,但是它被替换为使用#include<...>
而不是#include"..."
包含的下一个库。
I feel like this could lead me down a rabbit hole of replacing nearly all instances of #include<...>
with #include"..."
which would take ages. 我觉得这可能会让我#include<...>
用#include"..."
取代几乎所有#include<...>
实例,这需要很长时间。 Is there a setting I can change or a piece of code I could include that would sort this out? 是否有我可以更改的设置或我可以包含的一段代码可以解决这个问题?
Or could I just get rid of all the other unnecessary libraries and change the ones I need (I know that, that would still be a lot as they seem to rely on each other). 或者我可以摆脱所有其他不必要的库并改变我需要的库(我知道,这仍然会很多,因为它们似乎相互依赖)。
I have Boost library version 1.58.0. 我有Boost库版本1.58.0。
First you should read about the difference between #include "filepath"
and #include <filepath>
here . 首先,你应该阅读有关之间的差异#include "filepath"
和#include <filepath>
这里 。
Personally, I'm working with Boost from Visual Studio as follows: 就个人而言,我正在使用Visual Studio中的Boost,如下所示:
boost
library root (in my case C:\\Program Files (x86)\\Boost_1_53
). 转到项目属性 → C / C ++ → 常规 → 其他包含目录 ,并添加一个指向boost
库根目录的路径(在我的情况下为C:\\Program Files (x86)\\Boost_1_53
)。 #include <boost/lexical_cast/lexical_cast_old.hpp>
在源代码中包含.hpp文件,例如#include <boost/lexical_cast/lexical_cast_old.hpp>
If you're using non headers-only libraries you should also add path to Boost libraries in Project properties → Linker → General → Additional Libraries Directories . 如果您使用的是非标题库,则还应在项目属性 → 链接器 → 常规 → 附加库目录中添加Boost库的路径。
For example: 例如:
c:\\boost\\boost_1_58_0
(run booststrap.bat
and b2
as administrator). Boost库 - c:\\boost\\boost_1_58_0
(以管理员c:\\boost\\boost_1_58_0
运行booststrap.bat
和b2
)。 $(THIRD_PARTY)\\boost\\boost_1_58_0\\include
and $(THIRD_PARTY)\\boost\\boost_1_58_0\\
to VC++ Directories → Include Directories 将字符串$(THIRD_PARTY)\\boost\\boost_1_58_0\\include
和$(THIRD_PARTY)\\boost\\boost_1_58_0\\
到VC ++目录 → 包含目录 In Visual Studio 2012, right-click on your project and select "Properties". 在Visual Studio 2012中,右键单击项目并选择“属性”。
In the properties dialog, select "Configuration Properties" and then "VC++ Directories". 在属性对话框中,选择“配置属性”,然后选择“VC ++目录”。
You will need to add the Boost include path to the "Include Directories" list. 您需要将Boost包含路径添加到“包含目录”列表中。
If you're using all header-only libraries then you're done. 如果您使用的是所有仅限标题的库,那么您就完成了。 Otherwise, you will need to add the Boost library path to "Library Directories". 否则,您需要将Boost库路径添加到“Library Directories”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.