【问题标题】:C++ mysql and boost asio header conflictC++ mysql和boost asio头冲突
【发布时间】:2009-08-03 13:08:21
【问题描述】:

mysql c-api 和 boost::asio 之间的 windows 标头似乎有冲突。

如果我先包含 mysql,我会得到:

boost/asio/detail/socket_types.hpp(27) : 致命错误 C1189: #error : WinSock.h 已包含

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

如果我首先包含 boost::asio,我会得到:

include\config-win.h(24) : 警告 C4005: '_WIN32_WINNT' : 宏重新定义

/* 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

有没有办法解决这个问题,为什么 mysql 试图强制 windows 版本和 boost 试图强制它包含 winsock 本身?

【问题讨论】:

    标签: c++ mysql boost-asio


    【解决方案1】:

    试试

    #include "winsock2.h"

    在包含 mysql 和 boost::asio 之前

    【讨论】:

    • boost 包括很好,​​但 mysql 给出了警告,然后是 ws2tcpip.h 和 mswsock.h 中的一堆错误
    【解决方案2】:

    宏重新定义只是一个警告。您的代码仍应编译和链接。 我认为您的代码甚至可以毫无问题地运行。

    【讨论】:

      【解决方案3】:

      如果您找不到解决此问题的方法,您可以尝试将 MySQL API 封装在 opaque pointer 后面作为最后的手段。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多