Page 1 of 1

Winsock2 linker error

Posted: Fri Aug 13, 2010 2:01 am
by pritam
So I just started to write some stuff for IRC with WS2 and Visual Studio Express 2008, as usual I forgot to add that additional library "WS2_32.Lib" in the project options and got some linker errors and had Marcel help me out (again, thanks), but I wonder, why is this necessary? Why doesn't the header file for winsock handle that sort of thing?

Re: Winsock2 linker error

Posted: Fri Aug 13, 2010 2:37 am
by Milch
You mean why doesnt the header file include the libs?
Good question, I think this is because you would have to declare your path to the lib inside the .h file ( e.g #link LibLib.Lib ) - so if multiple people work on the same project that would be pretty annoying to change it all the time. But I think there was a preprocessor command in VC that did something like this.

Or why do you have to link the libs?
In the Header you tell the compiler "Hey, there is a function 'XYZ' but its stored somewhere different."
During compilation all your c/cpp files are 'converted' into object files and 'linked' together.
If the linker doesnt find the function you showed him in the header, it throws an error.

Re: Winsock2 linker error

Posted: Sat Aug 14, 2010 3:39 am
by pritam
I think that pretty much answered what I wanted to know, thanks ;)