Compiling a project for client/server [Linker error] undefined reference to-Collection of common programming errors
I am new to c++ and I am trying to connect to a server (127.0.0.1:4444). When I try to compile this code I get:
[Linker error] undefined reference to WSASartup@8
[Linker error] undefined reference to socket@12
[Linker error] undefined reference to inet_addr@4
[Linker error] undefined reference to etc…
The code:
#include
#pragma comment(lib, "ws2_32.lib")
int main()
{
WSADATA WSAData;
SOCKET sock;
SOCKADDR_IN sin;
char buffer[255];
WSAStartup(MAKEWORD(2,0), &WSAData);
sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_addr.s_addr = inet_addr("127.0.0.1");
sin.sin_family = AF_INET;
sin.sin_port = htons(4444);
connect(sock, (SOCKADDR *)&sin, sizeof(sin));
recv(sock, buffer, sizeof(buffer), 0);
closesocket(sock);
WSACleanup();
return 0;
}
Where are my mistake?
Originally posted 2013-11-27 11:51:28.