• Welcome to Valhalla Legends Archive.
 

Stupid Question Bothering me

Started by TheNewOne, September 06, 2005, 08:50 PM

Previous topic - Next topic

TheNewOne

Ok on other compilers I have no problem with this but im getting a linked error and im looking for some insight.


Linking...
Project1.obj : error LNK2001: unresolved external symbol _connect@12
project1.obj : error LNK2001: unresolved external symbol _htons@4
project1.obj : error LNK2001: unresolved external symbol _gethostbyname@4
project1.obj : error LNK2001: unresolved external symbol _socket@12
project1.obj : error LNK2001: unresolved external symbol _WSAStartup@8
project1.obj : error LNK2001: unresolved external symbol _closesocket@4
project1.obj : error LNK2001: unresolved external symbol _send@16
Debug/project1.exe : fatal error LNK1120: 7 unresolved externals
Error executing link.exe.

My Code is at work this is all i can provide sorry for the inconvience.

p.s. IT seems to give me the same error if i include winsock2.h or not so thats what confuses me.

Kp

You must also direct the compiler to link in the WinSock library.  Unlike on proper Unix systems, socket support is not in the default library.  If you were using MinGW, I'd tell you to add -lws2_32 to the command line.  Microsoft's linker syntax is wrong though, so that won't work for you.  Look around in the "Linker input" section of your project.  Find a list of libraries (ought to see kernel32.lib, user32.lib, gdi32.lib, etc. in there)  Add " ws2_32.lib" at the end of the list and your project should work fine.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

R.a.B.B.i.T

Project > Settings : "Link" Tab
Add "ws2_32.lib" to the end of the box under "Object/library modules"
MSVC++, of course.

Kp

Sure, if you're still using something outdated like VC6. :)  VC7 has a completely different way of specifying it, which is why I gave him vague version-independent guidance.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

K

Whenever I'm working in a Visual Studio environment, my favorite way to link to a library is:

#pragma comment(lib, "ws2_32");


Becuase I don't have to leave the source file.