2

I use Windows 11 64 bits and Cygwin 64 bits.

I need to build a project using boost asio without POSIX libraries. The project is built using Eclipse CDT toolset.

I can't use the POSIX libraries here because of the constraints of the project but in another context, I use this project built with Cygwin using POSIX libraries installed from the Cygwin installer and it works well.

The following defined symbols are used in the command line :

__USE_W32_SOCKETS
_WIN32_WINNT=0x0A00
BOOST_WINDOWS

But it result in many errors :

In file included from /usr/include/boost/asio/detail/win_static_mutex.hpp:71,
                 from /usr/include/boost/asio/detail/static_mutex.hpp:23,
                 from /usr/include/boost/asio/detail/win_global.hpp:19,
                 from /usr/include/boost/asio/detail/global.hpp:23,
                 from /usr/include/boost/asio/impl/system_executor.hpp:19,
                 from /usr/include/boost/asio/system_executor.hpp:129,
                 from /usr/include/boost/asio/associated_executor.hpp:21,
                 from /usr/include/boost/asio.hpp:21,
                 from ../src/AsioExample.cpp:10:
/usr/include/boost/asio/detail/impl/win_static_mutex.ipp: In member function 'int boost::asio::detail::win_static_mutex::do_init()':
/usr/include/boost/asio/detail/impl/win_static_mutex.ipp:48:3: error: '_snwprintf' was not declared in this scope; did you mean 'vsniprintf'?
   48 |   _snwprintf(
      |   ^~~~~~~~~~
      |   vsniprintf
/usr/include/boost/asio/detail/impl/win_static_mutex.ipp:115:3: error: expected 'catch' before '__except'
  115 |   __except(GetExceptionCode() == STATUS_NO_MEMORY
      |   ^~~~~~~~
/usr/include/boost/asio/detail/impl/win_static_mutex.ipp:115:3: error: expected '(' before '__except'
  115 |   __except(GetExceptionCode() == STATUS_NO_MEMORY
      |   ^~~~~~~~
      |   (
/usr/include/boost/asio/detail/impl/win_static_mutex.ipp:115:3: error: expected type-specifier before '__except'
  115 |   __except(GetExceptionCode() == STATUS_NO_MEMORY
      |   ^~~~~~~~
/usr/include/boost/asio/detail/impl/win_static_mutex.ipp:115:11: error: expected ')' before '(' token
  115 |   __except(GetExceptionCode() == STATUS_NO_MEMORY
      |   ~~~~~~~~^
      |           )
/usr/include/boost/asio/detail/impl/win_static_mutex.ipp:115:11: error: expected '{' before '(' token
/usr/include/boost/asio/detail/impl/win_static_mutex.ipp:116:63: error: expected ';' before '{' token
  116 |       ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
      |                                                               ^
      |                                                               ;
  117 |   {
      |   ~  

I visited this thread : how-to-use-boost-asio-library-with-cygwin-64-bit

But the given solution is not what I want to get here.

As the boost asio documentation indicates that we need to add the flag __USE_W32_SOCKETS to build it, I suppose it is possible but I can't find the proper solution. Can someone give some hints to achieve this?

wohlstad
  • 12,661
  • 10
  • 26
  • 39
Yoann F
  • 96
  • 5
  • It seems they have separate block with [`#if defined(__MINGW32__)`](https://github.com/boostorg/asio/blob/6d6d5a53d2f9559f398954cde2ab093288edecfc/include/boost/asio/detail/impl/win_static_mutex.ipp#L78) guard. But doesn't cygwin come with mingw compiler and should [have it defined](https://stackoverflow.com/questions/2224334/gcc-dump-preprocessor-defines)? Maybe try to define it manually. – dewaffled Oct 19 '22 at 16:31
  • 2
    Obligatory reminder that [MSYS2](https://stackoverflow.com/q/30069830/2752075) exists, which is essentially a Cygwin shell with a non-cygwin compiler. They should ship ASIO as package. – HolyBlackCat Oct 19 '22 at 16:33

1 Answers1

0

As MSYS2 is a based on modified version of Cygwin, I achieved the build by installing MSYS2 and boost in this context. It works well and seems to be the best way to do that.

Thanks @HolyBlackCat for the reminder that MSYS2 exists.

Yoann F
  • 96
  • 5