My first: "error LNK2019: unresolved external symbol" yei!

I'm trying to compile a simple HTTP request sender/receiver, as part of my socket studying.

All the code can be found here:

http://www.madwizard.org/programming/tutorials/netcpp/6

The error I get is:

1
2
1>header_client.obj : error LNK2019: unresolved external symbol "void __cdecl FillSockAddr(struct sockaddr_in *,char const *,int)" (?FillSockAddr@@YAXPAUsockaddr_in@@PBDH@Z) referenced in function "bool __cdecl request_headers(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?request_headers@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>C:\Users\eidge\documents\visual studio 2010\Projects\header_client\Debug\header_client.exe : fatal error LNK1120: 1 unresolved externals


I'm using VS2010Pro.

I've got a main.cpp and http_client.h and http_client.cpp files.

main and http.cpp include http_client.h

This is http_client.h:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef MYHTTP
#define MYHTTP

#include <iostream>
#include <string>
#include <cstring>

#include <winsock2.h>
#include <ws2tcpip.h>
#pragma comment(lib, "Ws2_32.lib")

extern const int TEMP_BUFFER_SIZE;
extern const std::string DEF_SERVER_NAME;
extern const int  SERVER_PORT;
extern const int  TEMP_BUFFER_SIZE;
extern const char HEAD_REQUEST_PART1[];
extern const char HEAD_REQUEST_PART2[];

// IP number typedef for IPv4
typedef unsigned long IPNumber;

class SocketException
{
public:
    SocketException() {} 
    SocketException(const std::string &pMessage): m_pMessage(pMessage) {}
	virtual ~SocketException() {}

    std::string what() { return m_pMessage; }
private:
    std::string m_pMessage;
};

bool request_headers(const std::string &host);
IPNumber FindHostIp(const std::string &host);
void FillSockAddr(sockaddr_in *pSockAddr, const char *pServerName, int portNumber);

#endif 


This is the function defined in http_client.cpp that is giving the undefined linker error:

1
2
3
4
5
6
7
void FillSockAddr(sockaddr_in *pSockAddr, const string &pServerName, int portNumber)
{
    // Set family, port and find IP
    pSockAddr->sin_family = AF_INET;
    pSockAddr->sin_port = htons(portNumber);
    pSockAddr->sin_addr.S_un.S_addr = FindHostIp(pServerName);
}


I'd appreciate if anyone can help compile this.

Thanks,

Hugo Ribeira
closed account (DSLq5Di1)
1
2
// http_client.h
void FillSockAddr(sockaddr_in *pSockAddr, const char *pServerName, int portNumber);

1
2
// http_client.cpp
void FillSockAddr(sockaddr_in *pSockAddr, const string &pServerName, int portNumber) { .. }
Last edited on
What a pair of fresh eyes can do, I've ran this code from end to end trying to figure out some obscure problem...

Thank's and sorry for the stupid question,

Hugo Ribeira
Topic archived. No new replies allowed.