views:

475

answers:

3

There seems to be a conflict with the windows headers between the mysql c-api and boost::asio.

If I include mysql first I get:

boost/asio/detail/socket_types.hpp(27) : fatal error C1189: #error : WinSock.h has already been included

#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
# if defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)
#  error WinSock.h has already been included
# endif // defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)

If I include boost::asio first I get:

include\config-win.h(24) : warning C4005: '_WIN32_WINNT' : macro redefinition

/* Defines for Win32 to make it compatible for MySQL */
#ifdef __WIN2000__
/* We have to do this define before including windows.h to get the AWE API
functions */
#define _WIN32_WINNT     0x0500
#else
/* Get NT 4.0 functions */
#define _WIN32_WINNT     0x0400
#endif

Is there some way around this, and why is mysql trying to force the windows version and boost trying to enforce that it include winsock its self anyway?

+1  A: 

Try

#include "winsock2.h"

before including mysql and boost::asio

Alan
boost includes fine, but mysql gives that warning followed by a bunch of errors in ws2tcpip.h and mswsock.h
Fire Lancer
A: 

If you can't find a way to get around this problem, you could try wrapping the MySQL API behind an opaque pointer as a last resort.

rpg
+2  A: 

The macro redefinition is only a warning. Your code should still compile and link. I think your code will even work without any problem.

Modicom