我正在尝试在 Windows 上使用 boost 1.54.0 并遇到了 asio::deadline_timer 的一些问题。
这是我的(非常简单的)代码:
#include <boost/asio.hpp>
using boost::asio::deadline_timer;
int main() {
deadline_timer timeout;
}
当我尝试使用 gcc 4.7 (cygwin) 编译此代码段时,会发生以下错误:
g++ -D__USE_W32_SOCKETS -D_WIN32_WINNT "-IC:\\dev\\lib\\boost_1_54_0" "-IC:\\dev\\workspace-cpp\\ts_core\\src" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\main.o" "..\\src\\main.cpp"
In file included from C:\dev\lib\boost_1_54_0/boost/asio/detail/impl/posix_tss_ptr.ipp:24:0,
from C:\dev\lib\boost_1_54_0/boost/asio/detail/posix_tss_ptr.hpp:77,
from C:\dev\lib\boost_1_54_0/boost/asio/detail/tss_ptr.hpp:27,
from C:\dev\lib\boost_1_54_0/boost/asio/detail/call_stack.hpp:20,
from C:\dev\lib\boost_1_54_0/boost/asio/impl/handler_alloc_hook.ipp:19,
from C:\dev\lib\boost_1_54_0/boost/asio/handler_alloc_hook.hpp:80,
from C:\dev\lib\boost_1_54_0/boost/asio/detail/handler_alloc_helpers.hpp:21,
from C:\dev\lib\boost_1_54_0/boost/asio/detail/bind_handler.hpp:19,
from C:\dev\lib\boost_1_54_0/boost/asio/detail/wrapped_handler.hpp:18,
from C:\dev\lib\boost_1_54_0/boost/asio/io_service.hpp:25,
from C:\dev\lib\boost_1_54_0/boost/asio/basic_io_object.hpp:19,
from C:\dev\lib\boost_1_54_0/boost/asio/basic_socket.hpp:20,
from C:\dev\lib\boost_1_54_0/boost/asio/basic_datagram_socket.hpp:20,
from C:\dev\lib\boost_1_54_0/boost/asio.hpp:21,
from ..\src\main.cpp:8:
C:\dev\lib\boost_1_54_0/boost/asio/error.hpp:77:17: error: a function call cannot appear in a constant-expression
C:\dev\lib\boost_1_54_0/boost/asio/error.hpp:130:15: error: a function call cannot appear in a constant-expression
C:\dev\lib\boost_1_54_0/boost/asio/error.hpp:135:19: error: a function call cannot appear in a constant-expression
C:\dev\lib\boost_1_54_0/boost/asio/error.hpp:149:23: error: a function call cannot appear in a constant-expression
C:\dev\lib\boost_1_54_0/boost/asio/error.hpp:163:15: error: a function call cannot appear in a constant-expression
..\src\main.cpp: In function 'int main()':
..\src\main.cpp:24:17: error: no matching function for call to 'boost::asio::basic_deadline_timer<boost::posix_time::ptime>::basic_deadline_timer()'
我花了一些时间研究并添加了“-D__USE_W32_SOCKETS -D_WIN32_WINNT”,但没有成功。问题似乎是 main.cpp 中的第 8 行“#include”行