Hello all. I'm trying to compile a socket program in DevC++ but everytime I do it I get a lot of linker errors like these:
[Linker error] undefined reference to `WSAStartup@8'
[Linker error] undefined reference to `htons@4'
[Linker error] undefined reference to `inet_pton'
[Linker error] undefined reference to `socket@12'
I have previously run the socket program successfully in Linux but I have to export it to WindowsXP, and I must admit I'm relatively new to programming in WindowsXP. These are the header files I used in the WindowsXP version:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
//#include <winsock.h>
#include <winsock2.h>
#include <stdio.h>
#include <string.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
// Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Mswsock.lib")
#pragma comment (lib, "AdvApi32.lib")
I just found those header files in sample socket programs in the internet and I don't know if I really need all of them, and whether I should use winsock.h or winsock2.h. I also learned that to solve these linker problems I need to link the libraries to the program and that's my main problem now. How do I link the libraries in WindowsXP and make the program in DevC++ work? By the way I'm using C programming language. Please help me solve this problem. Thanks!