Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

[SOLVED] Linker Error When Initializing Winsock

$
0
0
Hi,

I'm trying to write a small program to fetch a .txt file from a URL. I know that there are easier ways to do it than messing around with sockets, but I want to take the opportunity to learn.

I'm following a guide from MSDN using Microsoft Visual C++ 2010

I have the following code.

Main CPP File
// MAIN.CPP

#include "stdio.h"
#include "Connector.h"
#include "stdafx.h"

int main()
{
	Connector conn;
	conn.initializeSocket();
	return 0;
}




Connector.h
//Connector.h

#ifndef connector_H
#define connector_H

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>


class Connector
{
public:
	void initializeSocket();
};

#endif



Connector.cpp
#include "stdafx.h"
#include "Connector.h"

void Connector::initializeSocket()
{
	WSADATA wsaData;
	int iResult;

	iResult = WSAStartup(MAKEWORD(2,2), &wsaData);

	if (iResult != 0) {
		printf("WSAStartup failed: %d\n", iResult);
		return 1;
	}
}



The error I'm getting is:

Quote

error LNK2019: unresolved external symbol "public: void __thiscall Connector::initializeSocket(void)" (?initializeSocket@Connector@@QAEXXZ) referenced in function _main
C:\Users\...\Main.exe : fatal error LNK1120: 1 unresolved externals


Thanks for taking the time to look at this :)/>

Cbeppe.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>