cygwin Windows 10错误“ sigfillset在范围”中没有声明

Cygwin + windows 10 error "sigfillset was not declared in the scope"

本文关键字:声明 范围 Windows 错误 sigfillset cygwin      更新时间:2023-10-16

我正在尝试使用Cygwin在Windows上编译代码。当前代码在Linux上成功编译。这是我遵循的步骤来编译Windows 10上的代码。

1)我在Windows 10机器上安装了Cygwin。2)从Cygwin的安装程序包中安装了GCC,G 。3)在环境变量中添加了Cygwin路径。当我编译代码时,它会引发以下错误。

usr/include/boost/asio/detail/posix_signal_blocker.hpp: In constructor ‘boost::asio::detail::posix_signal_blocker::posix_signal_blocker()’:
/usr/include/boost/asio/detail/posix_signal_blocker.hpp:42:25: error: ‘sigfillset’ was not declared in this scope
     sigfillset(&new_mask);
                         ^
/usr/include/boost/asio/detail/posix_signal_blocker.hpp: In member function ‘void boost::asio::detail::posix_signal_blocker::block()’:
/usr/include/boost/asio/detail/posix_signal_blocker.hpp:59:27: error: ‘sigfillset’ was not declared in this scope
       sigfillset(&new_mask);
                           ^
In file included from /usr/include/boost/asio/detail/signal_set_service.hpp:213:0,
                 from /usr/include/boost/asio/signal_set_service.hpp:20,
                 from /usr/include/boost/asio/basic_signal_set.hpp:24,
                 from /usr/include/boost/asio.hpp:27,
                 from ../src/app/macl/net/TrxcomInboundReader.h:10,
                 from ../src/app/macl/net/TrxcomInboundReader.cc:1:
/usr/include/boost/asio/detail/impl/signal_set_service.ipp: In member function  boost::system::error_code boost::asio::detail::signal_set_service::add(boost::asio::detail::signal_set_service::implementation_type&, int, boost::system::error_code&)’:
/usr/include/boost/asio/detail/impl/signal_set_service.ipp:266:29: error: ‘sigfillset’ was not declared in this scope
       sigfillset(&sa.sa_mask);
                             ^
/usr/include/boost/asio/detail/impl/signal_set_service.ipp:267:44: error: no matching function for call to ‘sigaction::sigaction(int&, sigaction*, int)’
       if (::sigaction(signal_number, &sa, 0) == -1)
                                            ^
In file included from /usr/include/sys/signal.h:112:0,
                 from /usr/include/signal.h:6,
                 from /usr/include/pthread.h:12,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/x86_64-pc-cygwin/bits/gthr-default.h:35,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/x86_64-pc-cygwin/bits/gthr.h:148,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/ext/atomicity.h:35,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/basic_string.h:39,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/string:52,
                 from /usr/include/boost/core/demangle.hpp:14,
                 from /usr/include/boost/core/typeinfo.hpp:119,
                 from /usr/include/boost/detail/sp_typeinfo.hpp:20,
                 from /usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp:27,
                 from /usr/include/boost/smart_ptr/detail/sp_counted_base.hpp:5 ,
                 from /usr/include/boost/smart_ptr/detail/shared_count.hpp:29,
                 from /usr/include/boost/smart_ptr/shared_ptr.hpp:28,
                 from /usr/include/boost/shared_ptr.hpp:17,
                 from ../src/app/macl/net/TrxcomInboundReader.h:8,
                 from ../src/app/macl/net/TrxcomInboundReader.cc:1:
/usr/include/cygwin/signal.h:317:8: note: candidate: sigaction::sigaction()
 struct sigaction
        ^
/usr/include/cygwin/signal.h:317:8: note:   candidate expects 0 arguments, 3 provided
/usr/include/cygwin/signal.h:317:8: note: candidate: sigaction::sigaction(const sigaction&)
/usr/include/cygwin/signal.h:317:8: note:   candidate expects 1 argument, 3 provided
In file included from /usr/include/boost/asio/detail/signal_set_service.hpp:213:0,
                 from /usr/include/boost/asio/signal_set_service.hpp:20,
                 from /usr/include/boost/asio/basic_signal_set.hpp:24,
                 from /usr/include/boost/asio.hpp:27,

让我知道您的建议。

如果您查看cygwin的signal.h,您会看到sigactionsigfillset(您的错误消息说缺少了两个功能),在后卫中定义了:

#if __BSD_VISIBLE || __XSI_VISIBLE >= 4

这两个名称被双重编写,以表明您不应该直接将它们设置为自己。因此,请参见features.h,其中解释了更多。

因此,您需要将这两个内容之一添加到汇编命令中:

-D_XOPEN_SOURCE_EXTENDED

-D_GNU_SOURCE

-D_BSD_SOURCE

然后,丢失的功能将用于提升。代码中的某个地方可能有一些定义,可以在上述示例中抢占上述示例,如果您在任何可以阻止其工作的地方定义了_POSIX_SOURCE