linking error in "winsock2.h"

Started by
4 comments, last by hplus0603 18 years, 5 months ago
i just have start learning programming winsocket using visual studio 2003 but just in the begining i had some prp i have wrote this code: #include "stdafx.h" #include "winsock2.h" using namespace std ; void main() { WSADATA wsaData; int iResult = WSAStartup( MAKEWORD(2,2), &wsaData ); if ( iResult != NO_ERROR ) printf("Error at WSAStartup()\n"); } and it just keep telling me this error winsocket error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function _main i just think that the prp is that i have to link the winsock2.h but the prp that i dont know how should i download something .lib and then add a reference to my project or what i will appreciate ur help
Advertisement
Link to ws2_32.lib, it doesn't seem like you're doing that.
Hmmmm, if I recall correctly, you need to include "windows.h" before "winsock2.h". But since that's a linker error, I'm not sure if that would solve your problem.

The only thing I know is that I had problems not including windows.h.
STOP THE PLANET!! I WANT TO GET OFF!!
This sounds like a question about how to properly use MSVC, rather than a question about networking or multiplayer programming. You would probably get better help from a forum dedicated to tools help...

Actually, you typically want to include <winsock2.h> before you include <windows.h> to avoid some naming conflicts. <windows.h> is typically compiled into the precompiled headers, so you should add <winsock2.h> into your "stdafx.h" file, before that includes <windows.h>.

The link error is likely because you haven't added ws2_32.lib to the list of libraries to include, in the Linker settings.
enum Bool { True, False, FileNotFound };
ok guys but still have a trivial prp that i did not know how to include that
lib to the project
where to find it ?
Open MSVC.
Open the online help.
Search for "adding library to project".

Because this thread now has nothing to do with network programming, I'm going to close it; please find the appropriate forum for posting questions on how to use Visual Studio (or at least try reading the manual :-)
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement