Compilation errors with socket bind function

2019-08-14 05:25发布

问题:

At the very beginning I include the following files and everything goes fine with the bind function

#include "stdafx.h"
#undef UNICODE

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>

bind function

iResult = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen);

Things start messing up when I include the mysql libraries as well

#include "stdafx.h"
#undef UNICODE

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>

//mysql connections
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>

I started debug and it give me this error

IntelliSense: no suitable conversion function from "std::_Bind<false, void, SOCKET &, sockaddr *&, int>" to "int" exists    

error C2440: '=' : cannot convert from 'std::_Bind<false,void,SOCKET &,sockaddr *&,int>' to 'int'

Please help.

回答1:

I guess the problem is not in including the Mysql library, i got this problem once and i fixed it removing the

using namespace std;

or another solution is to call bind from the global namespace to avoid this kind of problems;

i forgot to write that calling bind from the global namespace is done like this :

::bind(...);

Hope this helps.