[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Win32 network programming in VC++ 6

Posted on 2002-07-04
10
Medium Priority
?
354 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and reading files 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

656 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