Solved

Win32 network programming in VC++ 6

Posted on 2002-07-04
10
350 Views
Last Modified: 2011-08-18
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
Comment
Question by:phirephly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 12

Expert Comment

by:pjknibbs
ID: 7131208
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
 

Author Comment

by:phirephly
ID: 7131344
will give it a whirl tomorrow during the day. I bet you're right... I'm so stupid :p
0
 

Expert Comment

by:weicco
ID: 7131347
Library's name is ws2_32.lib in Windows 98, NT, 2000 and XP. In CE it is winsock.lib.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:Mrxlazuardin
ID: 7132687
Use WSOCK32.LIB in your Link Library Setting.
0
 

Author Comment

by:phirephly
ID: 7133055
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
 

Author Comment

by:phirephly
ID: 7133056
nibbs already said that.
0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 7133617
If they both work with all the functions you're actually using, either answer is good enough, I'd say.
0
 

Accepted Solution

by:
weicco earned 100 total points
ID: 7135802
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
 

Expert Comment

by:dhanaspace1
ID: 7145854
have called the WSAStartup??
 
0
 

Author Comment

by:phirephly
ID: 7146949
So ws2_32.lib is the one to use. thanks everyone!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question