OS 为 Windows 7 X64,IDE 为Code::Blocks, 编译器为 mingw64, 使用 mysql,得到错误提示道:

"SOCKET" does not name a type

因为mysql是通过socket连接服务器的.在windows下,需要使用winsocket来连接. 因此需要在include mysql.h前加上

#include <winsock2.h>

所以最后结果就是下面这样子

#include <winsock2.h>
#include <mysql.h>

因为 mysql.h 中需要用到类型 SOCKET 但是在 windows 下需要显示声明

两个include顺序颠倒会导致依然错误

References:

  1. http://forums.mysql.com/read.php?45,270145,270145
  2. http://www.technowise.in/2009/08/fixing-socket-does-not-name-type-error.html
Categories: Code

Yu

Ideals are like the stars: we never reach them, but like the mariners of the sea, we chart our course by them.

Leave a Reply

Your email address will not be published.