简体   繁体   English

在Cygwin上编译Boost asio会发生很多错误

[英]Compiling Boost asio on cygwin occurs many errors

I train official Boost asio example( timer.cpp ) on cygwin. 我在cygwin上训练了官方的Boost asio示例( timer.cpp )。 And I want to compile it without creating any .lib or .dll and minimize dependencies for distributing by open-source. 而且我想在不创建任何.lib.dll情况下进行编译,并最小化通过开源分发的依赖性。 But when I copy only asio and config directories and asio.hpp and config.hpp files into libs directory(According the official manual, Boost asio requires only Boost config. Refer to Boost asio dependencies ), and compile the example with g++ timer.cpp -Ilibs -o timer , An error that there's no boost/version.hpp occurs. 但是,当我仅将asioconfig目录以及asio.hppconfig.hpp文件复制到libs目录中时(根据官方手册,Boost asio只需要Boost config。请参阅Boost asio依赖项 ),并使用g++ timer.cpp -Ilibs -o timer编译示例g++ timer.cpp -Ilibs -o timer ,发生没有boost/version.hpp的错误。

And I copy the omitted header and compile it... Similar error occurs again. 然后复制省略的标头并进行编译...再次发生类似错误。 And copy... occurs... copy... occurs... It's no end. 复制...发生...复制...发生...没有尽头。 So I copy all Boost libraries into libs , and compile it. 因此,我将所有Boost库复制到libs中并进行编译。 But I confused many and many errors and warnings occurs. 但是我很困惑很多错误和警告发生。 Despite I declare #define __USE_W32_SOCKETS and #define _WIN32_WINNT 0x0603 (I'm working on Windows 8.1) before #include <boost/asio.hpp> . 尽管我在#include <boost/asio.hpp>之前声明了#define __USE_W32_SOCKETS#define _WIN32_WINNT 0x0603 (我在Windows 8.1上工作)。 Following is final compile outputs. 以下是最终编译输出。 I'm getting tired. 我累了。

In file included from /usr/include/w32api/winsock2.h:56:0,
                 from libs/boost/asio/detail/socket_types.hpp:38,
                 from libs/boost/asio/detail/impl/winsock_init.ipp:22,
                 from libs/boost/asio/detail/winsock_init.hpp:125,
                 from libs/boost/asio/io_service.hpp:28,
                 from libs/boost/asio/basic_io_object.hpp:19,
                 from libs/boost/asio/basic_socket.hpp:20,
                 from libs/boost/asio/basic_datagram_socket.hpp:20,
                 from libs/boost/asio.hpp:21,
                 from src/main.cpp:4:
/usr/include/w32api/psdk_inc/_fd_types.h:100:2: warning: #warning "fd_set and     associated macros have been defined in sys/types.      This can cause runtime     problems with W32 sockets" [-Wcpp]
 #warning "fd_set and associated macros have been defined in sys/types.  \
  ^
In file included from libs/boost/asio/detail/impl/posix_tss_ptr.ipp:24:0,
                 from libs/boost/asio/detail/posix_tss_ptr.hpp:76,
                 from libs/boost/asio/detail/tss_ptr.hpp:27,
                 from libs/boost/asio/detail/call_stack.hpp:20,
                 from libs/boost/asio/impl/handler_alloc_hook.ipp:19,
                 from libs/boost/asio/handler_alloc_hook.hpp:80,
                 from libs/boost/asio/detail/handler_alloc_helpers.hpp:21,
                 from libs/boost/asio/detail/bind_handler.hpp:19,
                 from libs/boost/asio/detail/wrapped_handler.hpp:18,
                 from libs/boost/asio/io_service.hpp:24,
                 from libs/boost/asio/basic_io_object.hpp:19,
                 from libs/boost/asio/basic_socket.hpp:20,
                 from libs/boost/asio/basic_datagram_socket.hpp:20,
                 from libs/boost/asio.hpp:21,
                 from src/main.cpp:4:
libs/boost/asio/error.hpp:87:31: error: a function call cannot appear in     a constant-expression
           BOOST_ASIO_NATIVE_ERROR(ERROR_BROKEN_PIPE),

Summary: 摘要:

Q1. Q1。 Boost asio requires some other Boost libraries not only Boost config, but not all (I guess). Boost asio需要一些其他Boost库,不仅需要Boost配置,而且还不需要全部(我想)。 How to check library dependencies of Boost asio? 如何检查Boost asio的库依赖关系?

Q2. Q2。 On cygwin, Compiling timer example of Boost asio with g++ occurs many and many errors and warnings. 在cygwin上,使用g ++编译Boost asio的计时器示例会发生很多错误和警告。 But I'm according to official manual. 但是我根据官方手册。 How can I fix it? 我该如何解决?

Thanks. 谢谢。

According to the Boost Getting Started guide, Boost.Timer must be built, and users fecthing your code will need to install boost as well (your code or project mustn't worry about how boost is installed, juste indicate that it is needed). 根据Boost入门指南, 必须构建Boost.Timer ,并且感染了您的代码的用户也需要安装boost(您的代码或项目不必担心如何安装boost,只需指出它是必需的)。

You can use the static version to reduce external dependencies. 您可以使用静态版本来减少外部依赖性。 I've never done it with Cygwin but with MinGW, it should be equivalent. 我从未用Cygwin做到过,但在MinGW上,它应该是等效的。

Go into boost root directory, open a cmd.exe. 进入boost根目录,打开一个cmd.exe。

Your bin/ folder containing the compiler executables must be in your path. 包含编译器可执行文件的bin/文件夹必须在您的路径中。 If it is not, type this first: 如果不是,请首先输入以下内容:

SET PATH=%PATH%;<path to your cygwin bin folder here>

Now type: 现在输入:

bootstrap gcc

Then, when bootstrap has finished: 然后, bootstrap完成后:

b2 toolset=gcc variant=debug,release link=static threading=multi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM