遇到问题编制在Windows 7下面的C ++代码:
#include <boost/asio.hpp>
#include <iostream>
void handler1(const boost::system::error_code &ec)
{
std::cout << "5 s." << std::endl;
}
void handler2(const boost::system::error_code &ec)
{
std::cout << "10 s." << std::endl;
}
int main()
{
boost::asio::io_service io_service;
boost::asio::deadline_timer timer1(io_service, boost::posix_time::seconds(5));
timer1.async_wait(handler1);
boost::asio::deadline_timer timer2(io_service, boost::posix_time::seconds(10));
timer2.async_wait(handler2);
io_service.run();
}
我有MinGW的安装(GCC 4.8.1) c:\mingw
与我的PATH
设置正确。 我已经下载了升压和声明环境变量BOOST_ROOT
是它所在的路径。 我已经通过了bootstrap
和b2
程序提振。 我现在尝试编译:
c:\path\to\sandbox> g++ -I%BOOST_ROOT% -o main main.cpp
给出了一堆error: '::UnregisterWaitEx' has not been declared
错误
然后,我搜索了一下,看到我可能需要链接boost_system
。 所以:
c:\path\to\sandbox> g++ -I%BOOST_ROOT% -lboost_system -o main main.cpp
同样的错误。 想我会尝试指定库路径。 没有为boost_system一搜索,发现在静态库(libboost_system-mgw48-MT-1_55.a) %BOOST_ROOT%/stage/lib
。 所以
c:\path\to\sandbox> g++ -I%BOOST_ROOT% -L%BOOST_ROOT%/stage/lib -lboost_system-mgw48-mt-1_55 -o main main.cpp
同样的错误。 所以,我再次搜索,看其他人则建议追加-D-D_WIN32_WINNT=0x0601
。 所以
c:\path\to\sandbox> g++ -I%BOOST_ROOT% -L%BOOST_ROOT%/stage/lib -lboost_system-mgw48-mt-1_55 -o main main.cpp -D_WIN32_WINNT=0x0601
和不可避免的错误:
c:\mingw\include\mswsock.h:125:20: error: 'WSAPOLLFD' was not declared in this scope
int WSAAPI WSAPoll(WSAPOLLFD, ULONG, INT);
^
c:\mingw\include\mswsock.h:125:36: error: expected primary-expression before ',' token
int WSAAPI WSAPoll(WSAPOLLFD, ULONG, INT);
^
c:\mingw\include\mswsock.h:125:41: error: expected primary-expression before ')' token
int WSAAPI WSAPoll(WSAPOLLFD, ULONG, INT);
^
c:\mingw\include\mswsock.h:125:41: error: expression list treated as compound expression in initializer [-fpermissive]
我要去哪里错了?