Problems linking with purge virtuals


3>lib2.lib(GAME.obj) : error LNK2019: unresolved external symbol "public: virtual void __cdecl GAME::Allocate_Title(void)" (?Allocate_Title@GAME@@UEAAXXZ) referenced in function "public: __cdecl GAME::GAME(class ScrabStart const &)" (??0GAME@@QEAA@AEBVScrabStart@@@Z)

3>lib2.lib(TITLE.obj) : error LNK2019: unresolved external symbol "public: virtual void __cdecl TITLE::Allocate_Title_Tile(int,unsigned char)" (?Allocate_Title_Tile@TITLE@@UEAAXHE@Z) referenced in function "public: __cdecl TITLE::TITLE(void)" (??0TITLE@@QEAA@XZ)


What's weird is I have lots of pure virtuals. The program was working. I added a new TITLE class in lib2 and now it won't link. I have several layers of libraries. In general, classes in lib2 serve as the base classes for lib3. I have two versions of lib3. A text version and a Windows version.

New class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#pragma once

constexpr int TITLE_SIZE = 8;

class TITLE
{
protected:
	array<TILE *, TITLE_SIZE>		m_title_tiles;	

public: 
	TITLE();
	virtual ~TITLE();

	virtual void Allocate_Title_Tile(int n, LETTER ltr) = 0;
	virtual void Display() const = 0;	

};


And the derived class:
1
2
3
4
5
6
7
8
9
10
11
12
#pragma once

class WTITLE : public TITLE
{

public:
	WTITLE();
	virtual ~WTITLE() = default;

	void Display() const override;
	void Allocate_Title_Tile(int n, LETTER ltr) override;
};

Note that Display() is also pure virtual, but I don't get an undefined external on that.

And yes, WTILE::Allocacte_Title_Tiles() exists.

Any ideas?
unresolved external symbol means that you're calling Allocate_Title_Tile somewhere but you did not write a definition of the function.

Your sample code does not show any definition of the function, only declaration.

Did you define Allocate_Title_Tile?

Reason why you don't get unresolved external for Display() is because you do not call it anywhere, so definition is not needed.

EDIT:

How is LETTER defined?
If LETTER is defined as char* or wchar_t* then make sure you compile with or without UNICODE for all project equally.

If one lib is UNICODE but other is not then it means you link against non exported symbol, which is unresolved external symbol due to different function prototype.
Last edited on
Yes, Allocate_Title_Tile (int n, LETTER ltr) is defined:
LETTER is a typedef for unsigned char.

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
//	C++ Standard library
#include "pch.h"

#include "scrabwin.h"

void WTITLE::Allocate_Title_Tile(int n, LETTER ltr)
{
    //  Location of top tile
    int left = TITLE_LEFT;
    int top = (TOP_MARGIN_BOTTOM + (n * CELL_SIZE));
    int right = TITLE_LEFT + CELL_SIZE;
    int bottom = (TOP_MARGIN_BOTTOM + (n * CELL_SIZE) + CELL_SIZE);
    WTILE* wtile;

	TRACE_NEW (wtile, WTILE); 
	wtile->set_letter(ltr);
    wtile->set_rect(left, top, right, bottom);
    wtile->set_back_color(CR_WHITE);
    m_title_tiles[n] = wtile;
}

WTITLE::WTITLE()
{}

void WTITLE::Display () const
{   
    for (auto tile : m_title_tiles)
    {   //  Paint a title character
        tile->Display_Tile();        
    }
 }


Good thought regarding libraries having different UNICODE settings. I checked that and that's not the problem.
You said "I added a new TITLE class in lib2 and now it won't link"

Are you sure lib2 compiles the cpp file for the new class?
take a look at at build output and make sure it's compiled, it could be *.obj files are linked without cpp for TITLE class.
It looks like as if you call Allocate_Title_Tile(...) within the constructor of class TITLE which is wrong. The inherited function is not resolved at that time.
coder777 wrote:
It looks like as if you call Allocate_Title_Tile(...) within the constructor of class TITLE which ...

... will try to call the pure virtual function TITLE::Allocate_Title_Tile(...) and since you haven't provided an implementation for this function it will generate an unresolved external symbol error.

Good thinking! ️️👍
Last edited on
Thank you. That's what I missed.
Topic archived. No new replies allowed.