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

Windows sockets as viewed from a linux programmer, oh my

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 sock;
	struct sockaddr_in broadcastAddr;
	unsigned int broadcastPort;
	int recvStringLen;
	broadcastPort = 8004;
	if (sock < 0)
		printf("\nsocket() failed");
	// Still much more to come...
	return 0;

Open in new window

1 Solution
Todd MummertCommented:

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
ehensensAuthor Commented:
I found the easiest way was just to

#pragma comment(lib, "ws2_32.lib")
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now