C++ 如何包含 Boost 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29893307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I include Boost libraries?
提问by Peter
I'm trying to incorporate the Boost libraries into my program, specifically lexical_castand geometry. I include them using #include"boost/boost/geometry.hpp"and #include"boost/boost/lexical_cast/lexical_cast_old.hpp".
我试图将Boost库到我的程序,特别是lexical_cast和geometry。我使用#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. Is there a setting I can change or a piece of code I could include that would sort this out?
我觉得这可能会导致我失望更换几乎所有情况下的兔子洞#include<...>与#include"..."其中将采取的年龄。是否有我可以更改的设置或我可以包含的一段代码可以解决这个问题?
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。
采纳答案by kvorobiev
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,如下所示:
- Go to Project properties→ C/C++→ General→ Additional Include Directories, and add a path to the
boostlibrary root (in my caseC:\Program Files (x86)\Boost_1_53). - Include a .hpp file in your sources, like
#include <boost/lexical_cast/lexical_cast_old.hpp>
- 转到Project properties→ C/C++→ General→ Additional Include Directories,并添加到
boost库根目录的路径(在我的情况下C:\Program Files (x86)\Boost_1_53)。 - 在你的源文件中包含一个 .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.
如果您使用的是非头文件库,您还应该在Project properties→ Linker→ General→ Additional Libraries Directories 中添加 Boost 库的路径。
回答by Michael Popovich
For example:
例如:
- Boost library -
c:\boost\boost_1_58_0(runbooststrap.batandb2as administrator). - Add strings
$(THIRD_PARTY)\boost\boost_1_58_0\includeand$(THIRD_PARTY)\boost\boost_1_58_0\to VC++ Directories→ Include Directories
- Boost库-
c:\boost\boost_1_58_0(运行booststrap.bat,并b2为管理员)。 - 将字符串
$(THIRD_PARTY)\boost\boost_1_58_0\include和添加$(THIRD_PARTY)\boost\boost_1_58_0\到VC++ 目录→包含目录
回答by Ferruccio
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 库路径添加到“库目录”。

