Link to home
Start Free TrialLog in
Avatar of phirephly
phirephly

asked on

Win32 network programming in VC++ 6

I wanna write some networking jazz in VC++ (tho mostly just plain ol' C), which appears to require me to use mostly winsock calls. However, when I use examples I keep finding from books and tutes, I keep getting errors for all the networking calls. Below is the output. I get the same results using winsock.h or winsock2.h. The files do exist in the include directory under VC98. I think I have something set up wrong, but I have no idea what it would be. If the header files are (already) there, shouldn't VC be ready to go with it? I haven't changed the Winsock headers or anything, so that shouldn't be a problem. I tried deleting the files that VC generates (like server.obj) to see if they were just messed up and needed to be forced to be rebuilt, but no dice. Anybody know what's wrong or have any ideas? thanks and ttyl,

mich

--------------------Configuration: server_console - Win32 Debug--------------------
Compiling...
server.c
Linking...
server.obj : error LNK2001: unresolved external symbol _listen@8
server.obj : error LNK2001: unresolved external symbol _closesocket@4
server.obj : error LNK2001: unresolved external symbol _bind@12
server.obj : error LNK2001: unresolved external symbol _socket@12
server.obj : error LNK2001: unresolved external symbol _htons@4
server.obj : error LNK2001: unresolved external symbol _gethostbyname@4
server.obj : error LNK2001: unresolved external symbol _gethostname@8
server.obj : error LNK2001: unresolved external symbol _accept@12
Debug/server_console.exe : fatal error LNK1120: 8 unresolved externals
Error executing link.exe.

server_console.exe - 9 error(s), 0 warning(s)
Avatar of pjknibbs
pjknibbs

Just including the header file won't work--you need to include the LIBRARY file containing the code for the functions you're intending to call. In the case of WinSock this would probably be WSOCK32.LIB, so you need to add this library to the list of libraries which will be linked to your application.
Avatar of phirephly

ASKER

will give it a whirl tomorrow during the day. I bet you're right... I'm so stupid :p
Library's name is ws2_32.lib in Windows 98, NT, 2000 and XP. In CE it is winsock.lib.
Use WSOCK32.LIB in your Link Library Setting.
I started usin' wsock32.lib, then ws2_32.lib last night and all my problems went away... what's the difference between the two? I'm guessing ws2_32 is for winsock 2, and wsock32 is for winsock 1? I believe I saw somewhere last night that said that WS2 is backwards compatible, so would include WS1 stuff, is that correct? But then ws2 would also have the new stuff, so would ws2 be the better one (and thus make weicco the correct answer?) or should it be wsock32 after all, as nibbs suggested? thanks and ttyl,

mich

PS - sorry, I haven't been able to post this forever... I've been havin' a really hard time gettin' the server to respond!
nibbs already said that.
If they both work with all the functions you're actually using, either answer is good enough, I'd say.
ASKER CERTIFIED SOLUTION
Avatar of weicco
weicco

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
have called the WSAStartup??
 
So ws2_32.lib is the one to use. thanks everyone!