Sign in to follow this  
abdhk383

linking error in "winsock2.h"

Recommended Posts

abdhk383    122
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

Share this post


Link to post
Share on other sites
Structural    328
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.

Share this post


Link to post
Share on other sites
hplus0603    11347
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.

Share this post


Link to post
Share on other sites
hplus0603    11347
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 :-)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this