Reputation: 600
I´m trying to use boost 1.54.0 on Windows and got some problems with asio::deadline_timer.
Here´s my (quite simple) code:
#include <boost/asio.hpp>
using boost::asio::deadline_timer;
int main() {
deadline_timer timeout;
}
When I try to compile this snippet using gcc 4.7 (cygwin) the following errors occur:
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()'
I spent some time on research and added "-D__USE_W32_SOCKETS -D_WIN32_WINNT", but without success. The problem seems to be the line "#include " which is line 8 in main.cpp
Upvotes: 0
Views: 2074
Reputation: 6809
This rings a bell for me; I think I had to work around the same problem once. I believe that some of the error codes that ASIO uses are not specified in certain versions of Windows. Try using the following:
-D_WIN32_WINNT=0x0501
This targets the build to a minimum of Windows XP (I believe).
Upvotes: 1
Reputation: 600
Finally, it seems to be a problem of cygwin-gcc and building DLLs.
After I got some more very strange errors using boost, cygwin/gcc and eclipse (e.g. dynamic_pointer_cast not terminating, causing endless loop) I switched to VisualStudio '12 and everything worked like a charm...
Upvotes: 0
Reputation: 24576
It appears there is something wrong with the build configuration. The lines you mention all are calls to a BOOST_ASIO_WIN_OR_POSIX
macro which is the switch between calls to posix and native win implementation details. It seems your configuration somehow messes that up, includes the wrong headers and/or expands the macro wrong. The macro definition basically reads like this:
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
# define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_win
#else
# define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_posix
#endif
First question therefore: is __CYGWIN__
defined during your build?
Upvotes: 2
Reputation: 101
boost::asio::deadline_timer does not have default empty constructor. you should use:
boost::asio::io_service _iosvc;
boost::asio::deadline_timer timer(_iosvc);
Upvotes: 3