c++ - Cygwin + windows 10 错误 "sigfillset was not declared in the scope"

标签 c++ windows gcc boost g++

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

1) 我在我的 Windows 10 机器上安装了 Cygwin。 2) 从cygwin的安装包中安装了gcc、g++、boost。 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

然后缺少的功能将可用于 Boost。您的代码中某处可能有一些定义会抢占上述内容——例如,如果您在任何可能阻止其工作的地方定义了 _POSIX_SOURCE

关于c++ - Cygwin + windows 10 错误 "sigfillset was not declared in the scope",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41071016/

相关文章:

linux - 有没有办法重命名硬盘中的多个文件?

将打包的数据与对齐的内存访问相结合

c++ - WinRT C++ (Win10) 从 SoftwareBitmap/BitmapBuffer 访问字节

c++ - 标准容器中的抽象类

windows - 究竟为什么是 TranslateMessage

c++ - 错误 : no match for ‘operator+’ in ‘boost::filesystem::path::filename() const() + "/"’

c++11 - C++11 何时给出有关运算符优先级的警告?

C++,Linux : how to limit function access to file system?

c++ - 如何使用 C++ Boost 解析 JSON 数组?

python - 将 python 脚本作为 Windows 服务运行