1
votes

I'm getting these error messages

2>main.obj : error LNK2019: unresolved external symbol "public: __thiscall CEngine::CEngine(void)" (??0CEngine@@QAE@XZ) referenced in function _WinMain@16

2>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall CEngine::SetWindowSize(int,int,char const *,int)" (?SetWindowSize@CEngine@@QAEXHHPBDH@Z) referenced in function _WinMain@16

2>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall CEngine::Begin(void)" (?Begin@CEngine@@QAEXXZ) referenced in function _WinMain@16

2>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall CEngine::GetDisplayWidth(void)" (?GetDisplayWidth@CEngine@@QAEHXZ) referenced in function _WinMain@16

2>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall CEngine::GetDisplayHeight(void)" (?GetDisplayHeight@CEngine@@QAEHXZ) referenced in function _WinMain@16

2>C:\Users\ethan\Desktop\C++ Projects\delveenginetest\Debug\delveenginetest.exe : fatal error LNK1120: 5 unresolved externals

This is my solution:

Solution 'delveenginetest' (2 projects)

DelveEngine

Include

delve.h

Engine.h

SetupSDL.h

stdafx.h

Engine.cpp

Main.cpp

SetupSDL.cpp

This is the code for Engine.h

#pragma once
#include "SetupSDL.h"

class CEngine
{
public:
    CEngine(void);
    ~CEngine(void);

    void SetWindowSize(int winW, int winH, const char* GameName, int windowMode);
    void Begin(void);

    int GetDisplayWidth(void);
    int GetDisplayHeight(void);
private:
    int deskW;
    int deskH;

    bool playing;
    CSetupSDL* sdl_setup;
};

Code for Engine.cpp

#include "Include/stdafx.h"
#include "Include/Engine.h"

CEngine::CEngine(void)
{
    playing = true;

    deskW = GetSystemMetrics(SM_CXSCREEN);
    deskH = GetSystemMetrics(SM_CYSCREEN);
}


CEngine::~CEngine(void)
{
}

void CEngine::SetWindowSize(int winW, int winH, const char* GameName, int windowMode)
{
    // set up SDL for use
    sdl_setup = new CSetupSDL(winW, winH, GameName, windowMode);
}

void CEngine::Begin(void)
{
    while (playing && sdl_setup->GetMainEvent()->type != SDL_QUIT)
    {
        sdl_setup->Begin();
        sdl_setup->End();
    }

    playing = false;
}

int CEngine::GetDisplayWidth(void){ return deskW; }
int CEngine::GetDisplayHeight(void){ return deskH; }

The DelveEngine project builds successfully, whereas the delveenginetest project fails.

What's wrong? I've looked everywhere for a reason, can't find one that suits me.

1
I've seen that, and it doesn't help me in this caseuser3485645
Not relevant, but you don't need to say void for empty parameter lists in c++.πάντα ῥεῖ
I am aware of that. Help would be very nice.user3485645
'Help would be very nice.' Sorry, I can't spot what's wrong actually from the stuff you posted. This probably means the problem lies outside the information space you present here (which is inherently limited by your skills what to look after). I'm a bit suspicious about the 2 projects you're mentioning and what their relation actually is.πάντα ῥεῖ

1 Answers

1
votes

Despite the fact you're not providing all the sufficient information for a correct diagnosis of your problems, I'll try to share what I could imagine that might be the reasons for the linker errors:

  1. I suppose the project delveenginetest you mention is meant to set up unit tests for the classes from the DelveEngine project.
  2. Since you have a Main.cpp in your DelveEngine project, I'd guess it's simply build as an executable (successfully).
  3. Your delveenginetest needs to link to the classes provided from the DelveEngine project, but that's actually not possible, since the .exe from DelveEngine can't be used for linking, you'll need a library to import it to another executable (the unit testing framework).

I'd recommend to separate out your classes/source files from DelveEngine project to make up a static or shared library, that can be linked from an application and the test framework simultaneously from within a single VS solution:

Solution 'DelveEngine' (3 projects)  
   DelveEngineLib (project [.lib/.dll])
      Include  
         delve.h   
         Engine.h   
         SetupSDL.h   
      Engine.cpp
      SetupSDL.cpp
   DelveEngine (project [.exe])
      Main.cpp
   delveenginetest (project [.exe])
      Main.cpp (TestFramework main definition)

Since I'm not very versed with it I don't know actually, if VS 2013 supports to setup projects consuming virtual resources (think of links to sources in the actual build environment), but this could be an alternative how to setup application and unit tests without need of an extra library.