Solved

Windows sockets as viewed from a linux programmer, oh my

Posted on 2009-05-08
2
230 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
2 Comments
 
LVL 11

Accepted Solution

by:
climbgunks earned 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cisco RSTP portfast 3 53
Tracking Down IP in VMware 41 97
How computer Arp Table gets populated. 21 87
Transfering files via a single Cat5 between two DOMAIN computers. 14 77
Even if you have implemented a Mobile Device Management solution company wide, it is a good idea to make sure you are taking into account all of the major risks to your electronic protected health information (ePHI).
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now