How to use boost asio library with Cygwin 64 bit

2020-07-22 09:45发布

I am running Windows 10 64bit. Cygwin is 64 bit.

I installed boost from cygwin package manager.

I tried to compile test.cpp:

#include <boost/asio.hpp>
int
main(int argc, char**argv)
{
    return 0;
}

using command

g++ -std=c++11 -Wall -g  -D__USE_W32_SOCKETS D_WIN32_WINNT=_WIN32_WINNT_WIN7 test.cpp -o test.exe

but compile fails. It looks like posix is being used.

Any ideas why this fails?

In file included from /usr/include/boost/asio/detail/fd_set_adapter.hpp:22:0,
             from /usr/include/boost/asio/detail/select_reactor.hpp:27,
             from /usr/include/boost/asio/detail/reactor.hpp:29,
             from /usr/include/boost/asio/detail/impl/task_io_service.ipp:24,
             from /usr/include/boost/asio/detail/task_io_service.hpp:198,
             from /usr/include/boost/asio/impl/io_service.hpp:71,
             from /usr/include/boost/asio/io_service.hpp:767,
             from /usr/include/boost/asio/basic_io_object.hpp:19,
             from /usr/include/boost/asio/basic_socket.hpp:20,
             from /usr/include/boost/asio/basic_datagram_socket.hpp:20,
             from /usr/include/boost/asio.hpp:21,
             from appcontrol.cpp:16:
/usr/include/boost/asio/detail/posix_fd_set_adapter.hpp:82:12: error: 'fd_set' does not name a type
   operator fd_set*()
            ^
/usr/include/boost/asio/detail/posix_fd_set_adapter.hpp:105:11: error: 'fd_set' does not name a type
   mutable fd_set fd_set_;
           ^
/usr/include/boost/asio/detail/posix_fd_set_adapter.hpp: In constructor 'boost::asio::detail::posix_fd_set_adapter::posix_fd_set_adapter()':
/usr/include/boost/asio/detail/posix_fd_set_adapter.hpp:42:14: error: 'fd_set_' was not declared in this scope
    FD_ZERO(&fd_set_);
             ^

1条回答
Summer. ? 凉城
2楼-- · 2020-07-22 10:12

Thanks to help from #cygwin IRC:

g++ -std=c++11 -Wall -g -D_XOPEN_SOURCE=500 test.cpp -o test.exe -lboost_system
查看更多
登录 后发表回答