Winsock2 linker error

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
pritam
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 991
Joined: Thu Nov 13, 2008 3:16 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Amiga, PSOne, NDS
Programming Language of Choice: C++
Location: Sweden

Winsock2 linker error

Post 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?
User avatar
Milch
Chaos Rift Junior
Chaos Rift Junior
Posts: 241
Joined: Sat Jul 11, 2009 5:55 am
Programming Language of Choice: C++
Location: Austria, Vienna

Re: Winsock2 linker error

Post 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.
Follow me on twitter!
pritam
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 991
Joined: Thu Nov 13, 2008 3:16 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Amiga, PSOne, NDS
Programming Language of Choice: C++
Location: Sweden

Re: Winsock2 linker error

Post by pritam »

I think that pretty much answered what I wanted to know, thanks ;)
Post Reply