0

This error has been reported many times but I couldn't find what I was looking for. The following are the build errors

error LNK2019: unresolved external symbol "public: enum CLASS_ID __thiscall smp::sampleAbs::getClassID(void)" (?getClassID@sampleAbs@smp@@QAE?AW4CLASS_ID@@XZ) referenced in function "public: virtual void __thiscall mockSmp::run(void)" (?run@mockSmp@@UAEXXZ)
error LNK2001: unresolved external symbol "public: enum CLASS_ID __thiscall smp::sampleAbs::getClassID(void)" (?getClassID@sampleAbs@smp@@QAE?AW4CLASS_ID@@XZ)  
error LNK2019: unresolved external symbol "public: __thiscall smp::sampleAbs::sampleAbs(enum CLASS_ID)" (??sampleAbs@smp@@QAE@W4CLASS_ID@@@Z) referenced in function "public: __thiscall mockSmp::mockSmp(void)" (??0mockSmp@@QAE@XZ)

And this is my code.

sampleAbs.h

typedef enum 
{
    //sample enum values

}CLASS_ID;

namespace smp {

class sampleAbs
{
public:
    sampleAbs(CLASS_ID classID);
    ~sampleAbs(void) {}
    CLASS_ID getClassID(void);
    virtual void run() = 0;

private:
    CLASS_ID m_classId;
};  
}

sampleAbs.cpp

#include "sampleAbs.h"

namespace smp {

sampleAbs :: sampleAbs(CLASS_ID classID)
{
    m_classID = classID;
}

CLASS_ID
sampleAbs:: getClassID(void)
{
    
    return m_classID;
}

}

mock_sampleAbs.h

#include "sampleAbs.h"
using namespace smp
class mockSmp : public sampleAbs
{
public:
    CLASS_ID m_classID = 1;
    mockSmp() : sampleAbs(m_classID){}
    ~mockSmp();

    void run()
    {
        m_classID = getClassID();
    }
};

test.cpp

#include "mock_sampleAbs.h"
#include "gtest/gtest.h"

using namespace cmd;

TEST(test_getCommandID00, FunctionCoverage)
{
    mockSmp mObj;
    mObj.run();
    EXPECT_EQ(1, mObj.m_commandID);
}

I am not sure what I'm doing wrong, possibly something stupid. Would appreciate any help. Thank you!

  • 3
    Is the source file `sampleAbs.cpp` part of your project? – Some programmer dude Jul 22 '20 at 13:09
  • 2
    The two unresolved symbols are both defined in sampleAbs.cpp, which kind of suggests that you aren't compiling or aren't linking that file. Can't see anything else wrong. – john Jul 22 '20 at 13:17
  • @john I have included both sampleAbs.cpp and sampleAbs.h files in Properties->VC++ Directories. Is there something else that I should be doing? – iamlost Jul 22 '20 at 14:06
  • @Some-programmer-dude Yes, it is the source file I'm trying to test using GTest framework – iamlost Jul 22 '20 at 14:07
  • @iamlost You shouldn't do either of those things. As Some Programmer Dude says you should add those files in your *project*. – john Jul 22 '20 at 15:01

0 Answers0