Hey,

Any Idea why this section of code would give me these linker errors using Visual Studio 05 in a console application and using winsock2.h:

error LNK2019: unresolved external symbol __imp__WSACleanup@0 referenced in function "void __cdecl CloseDevice(void)" (?CloseDevice@@YAXXZ)

error LNK2019: unresolved external symbol __imp__closesocket@4 referenced in function "void __cdecl CloseDevice(void)" (?CloseDevice@@YAXXZ)

error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function "void __cdecl StartDevice(void)" (?StartDevice@@YAXXZ)

[LIST=1]
static int    socket_fd;							//Socket File Descriptor
bool          portReady;


void StartDevice();
void CloseDevice();

void CloseDevice()
{
	closesocket(socket_fd);
	WSACleanup();
}

void StartDevice()
{
	WSADATA wsaData;
	int iResult;

	iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);

	if (iResult != 0) 
	{
		portReady = false;
		cout << "WSAStartup failed." << endl;
		CloseDevice();
	}
	else
		portReady = true; 
}[/LIST]

Thanks.

Nemo

>>Any Idea why this section of code would give me these linker errors
Yes. You have to add Use Ws2_32.lib as described in the Requirements section here

I read thru the link and am still quite confused. Do I have to find the dll and library and put them in my debug folder, or..... Sorry for the ambiguity, but I just really dont understand how to fix this. Thanks.

Nemo

No, all you have to do is tell the linker that it should use that library. There are several ways to do that but the easiest way is to add this near the top of the *.cpp file

#pragma message(lib, "ws2_32.lib");
This question has already been answered. Start a new discussion instead.