[英]Boost asio library for networking (http client)
I'm trying to compile a utility in C++ with Visual Studio 2015, which requires the Boost asio library for networking (http requests).我正在尝试使用 Visual Studio 2015 用 C++ 编译一个实用程序,它需要Boost asio库来进行网络连接(http 请求)。 The same solution includes a project to build this Boost asio library, but I had to download the boost_1_59_0.7z file.
相同的解决方案包括一个项目来构建这个 Boost asio 库,但我必须下载 boost_1_59_0.7z 文件。 So far, I was able to download it and built was good, but I found the build generated like 11 libs with different names (libboost_ chrono -vc140-mt-sgd-1_59.lib, and 10 more but with date_time, filesystem, log-setup, etc...).
到目前为止,我可以下载它,并建立很好,但我发现像11个库具有不同名称(libboost_计时-vc140-MT-SGD-1_59.lib,以及10以上,但与DATE_TIME,文件系统日志产生的构建-设置等...)。 On the other hand, the project that requires this lib is looking for a library named boost_1_59_0.lib, so my question is how do I know which of the generated libraries is the right one to use for networking (I don't see any name related with asio or networking...).
另一方面,需要这个库的项目正在寻找一个名为 boost_1_59_0.lib 的库,所以我的问题是我如何知道哪个生成的库适合用于网络(我没有看到任何名称与 asio 或网络相关...)。 I would appreciate any guidance on this.
我将不胜感激。
Thanks Gus谢谢格斯
The Boost.Asio doc : Boost.Asio 文档:
By default, Boost.Asio is a header-only library.
默认情况下,Boost.Asio 是一个只有头文件的库。 However, some developers may prefer to build Boost.Asio using separately compiled source code.
但是,一些开发人员可能更喜欢使用单独编译的源代码来构建 Boost.Asio。 To do this, add
#include <boost/asio/impl/src.hpp>
to one (and only one) source file in a program, then build the program withBOOST_ASIO_SEPARATE_COMPILATION
defined in the project/compiler settings.为此,请将
#include <boost/asio/impl/src.hpp>
到程序中的一个(且仅一个)源文件中,然后使用在项目/编译器设置中定义的BOOST_ASIO_SEPARATE_COMPILATION
构建程序。 Alternatively,BOOST_ASIO_DYN_LINK
may be defined to build a separately-compiled Boost.Asio as part of a shared library.或者,可以定义
BOOST_ASIO_DYN_LINK
来构建单独编译的 Boost.Asio 作为共享库的一部分。
So, by default Asio is header-file-only and for most uses does not require linking against any Boost library.因此,默认情况下 Asio 是仅头文件,并且对于大多数用途不需要链接任何 Boost 库。
But, boost Asio does depens on other boost components likt Boost.System, Boost.Thread(not nessesary) etc. to support better async operations and some error codes ( boost::system::error_code and boost::system::system_error).但是,boost Asio 确实依赖于其他 boost 组件,比如 Boost.System、Boost.Thread(not nessesary) 等,以支持更好的异步操作和一些错误代码(boost::system::error_code 和 boost::system::system_error) .
boost asio
is a header-only library but asio
networking depends upon boost system
for error messages, which isn't a header only library. boost asio
是一个只有头文件的库,但是asio
网络依赖于错误消息的boost system
,它不是一个只有头文件的库。 In short, your code needs to link to boost-system
and it may also require boost-chrono
for asio
timers.简而言之,您的代码需要链接到
boost-system
并且它可能还需要用于asio
计时器的boost-chrono
。
Note: boost
supports autolinking
in Visual Studio
;注意:
boost
支持Visual Studio
autolinking
; so you just need to add the path to the boost
library directory to the Library Directories
configuration properties, eg:所以你只需要将
boost
库目录的路径添加到Library Directories
配置属性中,例如:
$BOOST_ROOT\stage\lib
Where $BOOST_ROOT
is the directory where you installed boost
.其中
$BOOST_ROOT
是您安装boost
的目录。
You do not need to add boost-system
or boost-chrono
to Linker->Input->Additional Dependencies
.您不需要将
boost-system
或boost-chrono
到Linker->Input->Additional Dependencies
。 However, you may need to add Windows
networking libraries, such as: wsock32
and ws2_32
.但是,您可能需要添加
Windows
网络库,例如: wsock32
和ws2_32
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.