1

This really beats me and the Visual Studio 2008 is so brainless that it's not helpful with the following errors at all.

My C++ solution has several projects in it. One project has the base C++ class CCrashReporter in crashreporter.h and crashreporter.cpp files.

I need to derive another class from it that is located in another project in the same solution. So I do:

//From CrashReporter2.h
#pragma once
#include "..\BaseModules\CrashReporter.h"

class CCrashReporter2 :
    public CCrashReporter
{
public:
    CCrashReporter2(void);
    virtual ~CCrashReporter2(void);
};

and then:

//From crashreporter2.cpp
#include "StdAfx.h"
#include "CrashReporter2.h"


CCrashReporter2::CCrashReporter2(void):
CCrashReporter(ENTERY_PARAM_FOR_REPORTER2)
{
}

CCrashReporter2::~CCrashReporter2(void)
{
}

The above code compiled OK, but when the linker runs I get these:

1>CrashReporter2.obj : error LNK2019: unresolved external symbol "public: __thiscall CCrashReporter::CCrashReporter(int) blah-blah
1>CrashReporter2.obj : error LNK2019: unresolved external symbol "public: __thiscall CCrashReporter::~CCrashReporter(void) blah-blah
1>C:\Users\Dev\C++\ProjName123\Debug\Mod123.exe : fatal error LNK1120: 2 unresolved externals
ahmd0
  • 16,633
  • 33
  • 137
  • 233
  • 1
    Seem like `BaseModules/CrashReporter.cpp` is not part of your project, or you are not linking the library that contains it. – Bo Persson Jul 16 '12 at 06:05
  • http://stackoverflow.com/questions/11429971/unable-to-resolve-error-lnk2019-unresolved-external-symbol/11430008#11430008 – Luchian Grigore Jul 16 '12 at 06:06
  • @BoPersson: You got it! Thanks. It was pretty easy. I wish the error message said so. Do you want to post it as an answer? All I needed to do is to select the 2nd project, then go to Project -> Add Existing Item and select both .cpp and .h files from the base class. Doh :) – ahmd0 Jul 16 '12 at 06:19

1 Answers1

0

See the comment from Bo Persson. Each project needs to link with the correct files in one way or another. Either add the source files directly to the project, or make a static/dynamic library project that you link into the application.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Thanks. Although I'm not sure why do I need to make a static/dynamic library project. I compile all of projects together into separate exe's and here I'm just reusing the CCrashReporter class. I actually already do this with "shared" structs and defines in a SharedTypes.h file that is declared and used just like that class. How come that does not cause any linker errors? – ahmd0 Jul 16 '12 at 06:13