I am trying to develop a basic communicating link using windows sockets in visual studio.net2003... but it is showing an lnk2001 error.. is it necessary that have to get the platform SDK and install it before i can use winsock2.h????

Dani AI

Generated

As pointed out, the LNK2001 errors mean the Winsock import library is not being linked. The Platform (Windows) SDK is not required just to use the standard Winsock2 API — Visual Studio normally provides the headers and the import library — but the SDK can be installed if those files are missing or if newer socket APIs are needed.

To add the library in Visual Studio .NET 2003: open the Project Properties for the active configuration, find the Linker settings and the Input (or Additional Dependencies) field, and add Ws2_32.lib. Apply the change to the correct configuration (Debug/Release) or to All Configurations so both builds see the library. If the linker reports it cannot find the file, add the VC/lib or SDK \Lib folder to the Linker -> General -> Additional Library Directories. For older project formats, the same library can be added via Project -> Settings -> Linker -> Object/library modules.

As a convenient in-code alternative (avoids touching project pages), place the following once in a source file:

#pragma comment(lib, "Ws2_32.lib")

Also note two common pitfalls that cause follow-up problems: include <winsock2.h> before <windows.h> (or #define WIN32_LEAN_AND_MEAN before including windows.h) to prevent conflicts with winsock.h, and initialize the Winsock subsystem with WSAStartup(MAKEWORD(2,2), &wsaData) before any socket calls and call WSACleanup() when finished. Once the correct import library is linked for the active configuration, the unresolved externals in the build log should be resolved.

Recommended Answers

All 4 Replies

You probably just need to incude the appropriate .lib in your studio project. Without the link error, I don't know which .lib...)

You probably just need to incude the appropriate .lib in your studio project. Without the link error, I don't know which .lib...)

this is the link error it is showing:

Linking...
a.obj : error LNK2001: unresolved external symbol "int __stdcall connect(unsigned int,struct sockaddr const *,int)" (?connect@@$$J212YGHIPBUsockaddr@@H@Z)
a.obj : error LNK2001: unresolved external symbol "unsigned short __stdcall htons(unsigned short)" (?htons@@$$J14YGGG@Z)
a.obj : error LNK2001: unresolved external symbol "unsigned long __stdcall inet_addr(char const *)" (?inet_addr@@$$J14YGKPBD@Z)
a.obj : error LNK2001: unresolved external symbol "int __stdcall WSACleanup(void)" (?WSACleanup@@$$J10YGHXZ)
a.obj : error LNK2001: unresolved external symbol "int __stdcall WSAGetLastError(void)" (?WSAGetLastError@@$$J10YGHXZ)
a.obj : error LNK2001: unresolved external symbol "unsigned int __stdcall socket(int,int,int)" (?socket@@$$J212YGIHHH@Z)
a.obj : error LNK2001: unresolved external symbol "int __stdcall WSAStartup(unsigned short,struct WSAData *)" (?WSAStartup@@$$J18YGHGPAUWSAData@@@Z)
H:\Project\work\aa\Debug\aa.exe : fatal error LNK1120: 7 unresolved externals

Build log was saved at "file://h:\Project\work\aa\aa\Debug\BuildLog.htm"
aa - 8 error(s), 0 warning(s)


pls help....

You have to link with:

Ws2_32.lib.

You have to link with:

Ws2_32.lib.

could u pls tell me how i do that.. i am a beginner so have lots to learn

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.