mardi 24 février 2015

socket errors gcc can't get functions in WinSock2.h

I literally read every post on stackoverflow that is somewhat similar to my case and none worked. this is a snippet of IRC.cc after my modifications : (I am using library cpIRC if you want to see IRC.h its on google)



#include "IRC.h"

#ifdef __WIN32__
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
//#include <windows.h>
#pragma comment(lib,"ws2_32")


#else
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#define closesocket(s) close(s)
#define SOCKET_ERROR -1
#define INVALID_SOCKET -1
#endif

... code ... ERROR IS ON THIS LINE:
irc_socket=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (irc_socket==INVALID_SOCKET)
{
return 1;
}

...code ...


ERRORS are as such :



||=== Build: Debug in botv (compiler: GNU GCC Compiler) ===|
obj\Debug\IRC.o||In function `ZN3IRC5startEPciS0_S0_S0_S0_':|
C:\Users\aaa\Desktop\CPP\botv\IRC.cc|107|undefined reference to `socket@12'|
C:\Users\aaa\Desktop\CPP\botv\IRC.cc|112|undefined reference to `gethostbyname@4'|
C:\Users\aaa\Desktop\CPP\botv\IRC.cc|115|undefined reference to `closesocket@4'|
C:\Users\aaa\Desktop\CPP\botv\IRC.cc|120|undefined reference to `htons@4'|
C:\Users\aaa\Desktop\CPP\botv\IRC.cc|122|undefined reference to `connect@12'|
C:\Users\aaa\Desktop\CPP\botv\IRC.cc|125|undefined reference to `WSAGetLastError@0'|
C:\Users\aaa\Desktop\CPP\botv\IRC.cc|127|undefined reference to `closesocket@4'|
C:\Users\aaa\Desktop\CPP\botv\IRC.cc|137|undefined reference to `closesocket@4'|
obj\Debug\IRC.o||In function `ZN3IRC10disconnectEv':|
C:\Users\aaa\Desktop\CPP\botv\IRC.cc|163|undefined reference to `shutdown@8'|
C:\Users\aaa\Desktop\CPP\botv\IRC.cc|165|undefined reference to `closesocket@4'|
obj\Debug\IRC.o||In function `ZN3IRC12message_loopEv':|
C:\Users\aaa\Desktop\CPP\botv\IRC.cc|196|undefined reference to `recv@16'|
||=== Build failed: 11 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|


I have read tons of answers about winsock2.h that is how I ended up with the includes you see and their order. it is still showing the same error. Any suggestions would be greatly appreciated


Aucun commentaire:

Enregistrer un commentaire