I’m building a socket program in Visual Studio 2003 .NET
I #include <winsock2.h> header file but also noticed that I had to link in the WS2_32.lib to fix the unresolved winsock function errors.
In other homework projects, I just added a header file and used it’s functions – without adding the corresponding library.
How is this so?
Are some standard header file libraries already pre-linked in Visual Studio or something else?
Thank You!
The socket functions are actually implemented in
ws2_32.dll. In order for the linker to be able to find them, you need to add thews2_32.libimport library to your project. Note that the import library does not contain the actual code for the functions, but only information about where to find the actual functions (inws2_32.dll).You don’t mention which other header files you’re referring to, but if it’s something like
<string.h>then that is already in the MSVC runtime library; if it’s something like<windows.h>then those functions are provided by import libraries such askernel32.lib,user32.lib, andgdi32.lib. Those libraries are probably already included in your linker settings.