ffenix
ffenix

Reputation: 553

unresolved symbol trouble

I have the following project files:

//connections.cpp

#include "stdafx.h"
#include "LibraryHeaders.h"
#include "FileManager.h"

#define WSAVersion 0x202
#define GSMsgID 0x100

extern HWND Main_hWnd;

bool InitConnections ()
{
    FileManager::ConnectFile *connectfile = FileManager::ReadConnectFile(connectfile);
    SockBase GSConnection(WSAVersion, TCP, connectfile->GS_IP, connectfile->GS_Port, Main_hWnd, GSMsgID);
    if (GSConnection.Connect() != true) {return false;}
    return true;
}

//FileManager.cpp
#include "stdafx.h"
#include "FileManager.h"
#include "LibraryHeaders.h"

using namespace FileManager;

ConnectFile* ReadConnectFile(ConnectFile *ConnectStruct)
{
    FileLibrary connectfile("DMOConnection.cfg");
    if (connectfile.OpenFile(HEAP, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, PAGE_READWRITE) != true) {return false;}
    ConnectStruct->GS_IP = connectfile.parser->str_GetToken((char*)connectfile.FileBuff);
    if (ConnectStruct->GS_IP == (const char*) -1) {return false;}
    ConnectStruct->GS_Port = connectfile.parser->int_GetToken((char*)connectfile.FileBuff);
    if (ConnectStruct->GS_Port == -1) {return false;}
    return ConnectStruct;
}

//FileManager.h
namespace FileManager
{
    struct ConnectFile
    {
        const char* GS_IP;
        unsigned int GS_Port;
    };

    ConnectFile* ReadConnectFile(ConnectFile*);
}

And when trying to build the project i got this error:

Connections.obj : error LNK2019: unresolved external symbol "struct FileManager::ConnectFile * __cdecl FileManager::ReadConnectFile(struct FileManager::ConnectFile *)" (?ReadConnectFile@FileManager@@YAPAUConnectFile@1@PAU21@@Z) referenced in function "bool __cdecl InitConnections(void)" (?InitConnections@@YA_NXZ)

I dont understand why, the linker should look up and see that ive defined FileManager::ReadConnectFile on FileManager.cpp but it doesnt, any tip how to fix this?

Upvotes: 0

Views: 92

Answers (3)

nzav
nzav

Reputation: 1

The code

using namespace FileManager;
ConnectFile* ReadConnectFile(ConnectFile *ConnectStruct)
{ ...some definition...}

defines the ReadConnectFile function not in the namespace FileManager, but in global namespace.

Upvotes: 0

ffenix
ffenix

Reputation: 553

i fixed it by declaring the function out of the namespace:

namespace FileManager
{
    struct ConnectFile
    {
        const char* GS_IP;
        unsigned int GS_Port;
    };
}

using namespace FileManager;
ConnectFile* ReadConnectFile(ConnectFile *ConnectStruct);

The IDE is VC11 Beta, thanks for the answers.

Upvotes: 0

Luchian Grigore
Luchian Grigore

Reputation: 258648

You're defining a free function:

ConnectFile* ReadConnectFile(ConnectFile *ConnectStruct)

not a member:

ConnectFile* FileManager::ReadConnectFile(ConnectFile *ConnectStruct)

Totally different.

Also:

using namespace FileManager;

and

error LNK2019: unresolved external symbol "struct FileManager::ConnectFile [...]

suggests you have a namespace FileManager and a struct FileManager... any reason for using the same name?

Upvotes: 1

Related Questions