我正在尝试使用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,
让我知道你的建议。
答案 0 :(得分:4)
如果你看看Cygwin的signal.h
,你会发现.error()
和sigaction
(你的错误消息中所说的两个函数都缺失了)是在一个警卫中定义的:< / p>
sigfillset
这两个名字是双重强调的,表示你不应该自己直接设置它们。所以请参阅features.h
,其中解释了更多内容。
因此,您需要在编译命令中添加以下两项内容之一:
#if __BSD_VISIBLE || __XSI_VISIBLE >= 4
或者
-D_XOPEN_SOURCE_EXTENDED
或者
-D_GNU_SOURCE
然后缺少的功能将可用于Boost。您可能在代码中的某处有一些定义,这些定义优先于上述内容 - 例如,如果您在任何可能阻止其工作的地方定义了-D_BSD_SOURCE
。