error LNK2019 & LNK2001

Hi,
After fighting with compiler for 3 hours I still quiet figure this out. I keep getting these same errors over and over.

Basically, I have a static library that has handles most of object management and holds all base classes. The second (.exe) project either uses or derives new classes out of it. It was working like charm until i started implementing Vector2 struct. Here is how the problematic ones look.

// In Static Library //
GameObject.h
1
2
3
4
5
6
7
8
9
#include "DynamicBody.h"

class GameObject {
public:
	GameObject( );
	virtual ~GameObject( );
public:
	DynamicBody	 *_dynamic_body;
};


Gameobject.cpp
1
2
3
4
5
6
7
8
9
#include "GameObject.h"

GameObject::GameObject( ) {
	_dynamic_body = nullptr;
}

GameObject::~GameObject( ) {
	if ( _dynamic_body ) delete _dynamic_body;
}


DynamicBody.h
1
2
3
4
5
6
7
8
9
#include "Vector2.h"

class DynamicBody {
public:
	DynamicBody( );
	virtual ~DynamicBody( );

	Vector2	_velocity;
};


Vector2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
struct Vector2 {
public:
	float x;
	float y;	
	Vector2( );
	Vector2( const float inX, const float inY );

	virtual ~Vector2( );
	
	Vector2 add( const Vector2& inVec ) const;
	Vector2 operator+( const Vector2& inVec ) const;
	Vector2 operator+=( const Vector2& inVec );
};


DynamicBody.cpp
1
2
3
4
5
6
7
8
#include "DynamicBody.h"

DynamicBody::DynamicBody( ) {
	_velocity = Vector2( 0, 0 );
}

DynamicBody::~DynamicBody( ) {
}


Vector2.cpp
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
#include "Vector2.h"
#include "Index.h"
#include <math.h>

Vector2::Vector2( ) {
	x = 0.0f;
	y = 0.0f;
}

Vector2::Vector2( const float inX, const float inY ) {
	x = inX;
	y = inY;
}

Vector2 Vector2::add( const Vector2& inVec ) const {
	return Vector2(
		x + inVec.x,	
		y + inVec.y );
}

Vector2 Vector2::operator+( const Vector2& inVec ) const {
	return add( inVec );
}
	
Vector2 Vector2::operator+=( const Vector2& inVec ) {
	*this = *this + inVec;
	return *this;
}


// (.exe)Projecr //
Player.h
1
2
3
4
5
6
7
#include "GameObject.h"

class Player : public GameObject {
public:
	Player( );
	virtual ~Player( );
};


Player.cpp
1
2
3
4
5
6
7
8
9
10
#include "Player.h"

#include "DynamicBody.h"

Player::Player( ) {
	_dynamic_body = new DynamicBody( ); // Do this and Linker goes crazy
}

Player::~Player( ) {
}


1>Framework.lib(DynamicBody.obj) : error LNK2019: 未解決の外部シンボル "public: virtual __thiscall Vector2::~Vector2(void)" (??1Vector2@@UAE@XZ) が関数 __unwindfunclet$??0DynamicBody@@QAE@XZ$0 で参照されました。
1>Framework.lib(Vector2.obj) : error LNK2001: 外部シンボル ""public: virtual __thiscall Vector2::~Vector2(void)" (??1Vector2@@UAE@XZ)" は未解決です。


I know its in Japanese but its standard unresolved symbol error.

So... If I don't create new DynamicBody object linker doesn't complain but that is a no no. I need to use that.
And if I write all of Vector2 function definition in the struct definition solves the problem. But its also a no no since I want to make a Vector3 struct that has same functions.
What I don't get is why it suddenly can't link the .cpp file correctly but everything else is ok?

Thanks in advance.

Wolf
Last edited on
Where is Vector2's destructor defined?
Holly ********
It was all because of destructor? I can't believe this. OMG.
I am totally done for today.
Thanks Peter87. Proves the fact that you need fresh pair of eyes.

I am done.... I quit...
Wolf #rect.
Last edited on
Topic archived. No new replies allowed.