• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

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)
0
phirephly
Asked:
phirephly
  • 4
  • 2
  • 2
  • +2
1 Solution
 
pjknibbsCommented:
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.
0
 
phirephlyAuthor Commented:
will give it a whirl tomorrow during the day. I bet you're right... I'm so stupid :p
0
 
weiccoCommented:
Library's name is ws2_32.lib in Windows 98, NT, 2000 and XP. In CE it is winsock.lib.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
MrxlazuardinCommented:
Use WSOCK32.LIB in your Link Library Setting.
0
 
phirephlyAuthor Commented:
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!
0
 
phirephlyAuthor Commented:
nibbs already said that.
0
 
pjknibbsCommented:
If they both work with all the functions you're actually using, either answer is good enough, I'd say.
0
 
weiccoCommented:
Copy&Paste from MSDN:

  Header: Declared in winsock2.h.
  Import Library: Link with ws2_32.lib.

In Windows CE winsock.h and winsock.lib
0
 
dhanaspace1Commented:
have called the WSAStartup??
 
0
 
phirephlyAuthor Commented:
So ws2_32.lib is the one to use. thanks everyone!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now