Search code examples
c++boostboost-process

boost::process doesn't work in Cygwin


Trying to complie the following code in Cygwin environment:

#include <boost/process.hpp>

int main() { }

And get the following error:

In file included from /usr/include/boost/process/detail/child_decl.hpp:31:0,
                 from /usr/include/boost/process/child.hpp:21,
                 from /usr/include/boost/process/async_system.hpp:22,
                 from /usr/include/boost/process.hpp:24,
                 from bp.cpp:2:
/usr/include/boost/process/detail/posix/is_running.hpp:18:1: error: non-constant condition for static assertion
 static_assert(!WIFEXITED(still_active), "Internal Error");
 ^~~~~~~~~~~~~
In file included from /usr/include/cygwin/stdlib.h:13:0,
                 from /usr/include/stdlib.h:26,
                 from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/cstdlib:75,
                 from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ext/string_conversions.h:41,
                 from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/basic_string.h:6349,
                 from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/string:52,
                 from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/stdexcept:39,
                 from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/system_error:41,
                 from /usr/include/boost/process/detail/config.hpp:21,
                 from /usr/include/boost/process/detail/basic_cmd.hpp:10,
                 from /usr/include/boost/process/args.hpp:33,
                 from /usr/include/boost/process.hpp:22,
                 from bp.cpp:2:
/usr/include/boost/process/detail/posix/is_running.hpp:18:16: error: call to non-constexpr function 'int __wait_status_to_int(int)'
 static_assert(!WIFEXITED(still_active), "Internal Error");
                ^

Could you suggest how to fix it?

I'm using Boost 1.66.


Solution

  • The WIFEXITED macro expands to a function call to __wait_status_to_int. This one can't be called at compile time.

    This is a bug in boost process in Cygwin.

    According to

    https://github.com/openunix/cygwin/blob/master/winsup/cygwin/include/sys/wait.h

    __wait_status_to_int is a macro and for C++ they remove the macro and instead they provide two overloaded functions.