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

x
?
Solved

Windows sockets as viewed from a linux programmer, oh my

Posted on 2009-05-08
2
Medium Priority
?
239 Views
Last Modified: 2012-05-06
Hi all,

So I'm a novice network programmer by any means, but still all the network programming I've ever done has been in Linux / Cocoa. So, I'm curious as to why I can't even create a socket in my new windows application. I'm sure there's something dreadfully and obviously wrong with it. Can someone tell me what it is? I am being told:

Error      5      error LNK2001: unresolved external symbol _socket@12      responder.obj      Responder

Error      6      fatal error LNK1120: 1 unresolved externals


Thanks a bunch!
#include <stdio.h>
#include <winsock.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
 
 
int main()
{
	int MAXRECVSTRING = 255;
 
	int sock;
	struct sockaddr_in broadcastAddr;
	unsigned int broadcastPort;
	int recvStringLen;
 
	broadcastPort = 8004;
 
	sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if (sock < 0)
	{
		printf("\nsocket() failed");
		getch();
		exit(0);
	}
 
	// Still much more to come...
 
	return 0;
}

Open in new window

0
Comment
Question by:ehensens
[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
2 Comments
 
LVL 11

Accepted Solution

by:
Todd Mummert earned 2000 total points
ID: 24340890

the "unresolved external symbol" error means it's a linking error, not necessarily that there's anything wrong w/ your code.

In windows, you have to link against the winsock library, ws2_32.    Btw, you'll need to call the Windows Socket initializer, WSAStartup, before using the winsock API.

see http://msdn.microsoft.com/en-us/library/ms740506(VS.85).aspx for more info
0
 

Author Closing Comment

by:ehensens
ID: 31579663
I found the easiest way was just to

#pragma comment(lib, "ws2_32.lib")
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains the fundamentals of industrial networking which ultimately is the backbone network which is providing communications for process devices like robots and other not so interesting stuff.
Tech spooks aren't just for those who are tech savvy, it also happens to those of us running a business. Check out the top tech spooks for business owners.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

650 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