warning LNK4221 with VS2005 but not with VS2003

Started by
9 comments, last by Mikeske 17 years, 3 months ago
Hello ppl, As in my last post I'm setting up directx stuff etc in a static library, and was converting stuff over from an vs2003 project to my vs2005 project. when compiling it gave me an erro saying: LNK4221.... saying that cVector3.obj doesn't have public stuff and will there for not be accessible...at least what I make of it cVector3.h file

#ifndef VECTOR3_H
#define VECTOR3_H

#include "math.h"
#include "d3dx9math.h"

class cVector3	:	public D3DXVECTOR3
{
public:
	//Creators
	//--------
	cVector3(void){};
	cVector3 (const cVector3& vec)				: D3DXVECTOR3(vec.x, vec.y, vec.z){};
	cVector3 (float _x,float _y,float _z)		: D3DXVECTOR3(_x,_y,_z){};
	virtual ~cVector3(void){};

	//Operators
	//---------
	const cVector3& operator *= (const cVector3& vec);
	const cVector3& operator /= (const cVector3& vec);
	const cVector3& operator *= (float v);
	const cVector3& operator /= (float v);

	//Mutators
	//--------
	void set	(float _x,float _y ,float _z);
	void clear	(void);
	bool isClear()const;

	//Calculations/Operations
	//-----------------------

	//Length & distance calculations
	void Normalize();
	float Length()const;
	float LenghtSquared() const;

	//dot and cross product
	float dotProduct(const cVector3& _vec)const;
	void  crossProduct(const cVector3& _vec);
	void  crossProduct (const cVector3& _vecA, const cVector3& _vecB);
};
#endif


#include "Vector3.h"

const cVector3& cVector3::operator *= (const cVector3& vec)
{
	x *= vec.x;
	y *= vec.y;
	z *= vec.z;
	return(*this);
}

const cVector3& cVector3::operator *= (float v)
{
	x *= v;
	y *= v;
	z *= v;
	return(*this);
}

// divide

const cVector3& cVector3::operator /= (const cVector3& vec)
{
//	debug_assert(vec.x != 0.0f, "divide by zero error");
//	debug_assert(vec.y != 0.0f, "divide by zero error");
//	debug_assert(vec.z != 0.0f, "divide by zero error");

	x /= vec.x;
	y /= vec.y;
	z /= vec.z;
	return(*this);
}

const cVector3& cVector3::operator /= (float v)
{
//	debug_assert(v != 0.0f, "divide by zero error");

	x /= v;
	y /= v;
	z /= v;
	return(*this);
}

cVector3 operator * (float scalar, const cVector3 &a)
{
	return(cVector3((a.x * scalar), (a.y * scalar), (a.z * scalar)));
}

cVector3 operator * (const cVector3 &a, float scalar)
{
	return(cVector3((a.x * scalar), (a.y * scalar), (a.z * scalar)));
}

cVector3 operator - (const cVector3 &a, const cVector3 &b)
{
	return(cVector3((a.x - b.x), (a.y - b.y), (a.z - b.z)));
}

void cVector3::set(float _x, float _y, float _z)
{
	x = _x;
	y = _y;
	z = _z;
}

void cVector3::clear(void)
{
	x = 0.0f;
	y = 0.0f;
	z = 0.0f;
}

bool cVector3::isClear()const
{
	return (x == 0.0f)
		&& (y == 0.0f)
		&& (z == 0.0f);
}

void cVector3::Normalize()
{
	D3DXVec3Normalize(this,this);
}

float cVector3::Length()const
{
	return D3DXVec3Length(this);
}

float cVector3::LenghtSquared() const
{
	return D3DXVec3LengthSq(this);
}

float cVector3::dotProduct(const cVector3 &_vec) const
{
	return D3DXVec3Dot(this, &_vec);
}

void cVector3::crossProduct(const cVector3 &_vec)
{
	D3DXVec3Cross(this, this, &_vec);
}

void cVector3::crossProduct(const cVector3 &_vecA, const cVector3 &_vecB)
{
	D3DXVec3Cross(this, &_vecA, &_vecB);
}

Same thing with cVector2 (.h/.cpp) which have the same build up internally... I know for sure I didn't have this error before in my vc2003 project. Because, I could use internally in the lib the cvector2 and 3 -objects. Best regards and best wishes 2007 already people[attention][attention][attention]
Advertisement
I'd suggest that you do a google search about LNK4221. It might help. (I did it just now, but I'd have to ask if this is part of a static library, and other questions. It's be easier for you to just look at the links yourself.)
Quote:I'd suggest that you do a google search about LNK4221

Already did this, and to be honest, I can't see what I'm doing wrong here...
If I ask something it's because I'm through all regular channels (books/www/etc), so please be more constructive about the help plss.

For you ohter question, yes it is an static library.

So, if you ET3D or any other ppl could help me out on this one???

greetz
Hey,

I found already something on msdn-support but I can't figure out a solution how to work around it...

I can't imagine nobody of the code-gurus in here has a solution for it...[embarrass]
I don't know what you googled with, but "2003 2005 lnk4221" produces some good results.

However, there does not seem to be any concrete answers to the problem, aside from changing it into a dll.

Also, you might want to download a few static libraries from the net and see if they return the same error.
If you don't mind me asking, what is the point of this new class? It looks like you inherit from D3DXVector3 and then rewrite every single method to do what D3DXVector3 did anyway. Also, since everything will know go through a vtable lookup, it will be much less efficient.
Stay Casual,KenDrunken Hyena
DrunkenHyena,

You got a point over there, didn't know that it would be less efficient but sometimes the naming of directx is such a mess (my opinion) that I wanted to encapsulate it, to naming more clearly to me...

Greetz
Quote:Original post by DrunkenHyena
Also, since everything will now go through a vtable lookup, it will be much less efficient.

Nothing will be going through a vtable lookup, since he hasn't overridden anything.

Mikeske:
If you *really* want to do it this way, you should remove the 'virtual' keyword on the destructor. It adds an unnecessary vtable to your class.

But really, why are you doing this?! You're using the D3DX functions but they're all so basic that you might as well just implement the entire thing yourself. Or if you simply must use them, get rid of the inheritance and add the x, y, and z floats to your own class. Then use a reinterpret_cast to cast the this pointer to a D3DXVECTOR3 when you pass it in to the D3DX functions (for this to work you can't have any virtuals).

As to your link error: check that your project actually is set up as a static library. I've just been setting up a new static library for my own projects in VS 2005 Express and haven't had seen this error. The only thing I can think of is that maybe it's set as a DLL and nothing is marked as exported.

Cheers
Sam

[Edited by - izzo on January 1, 2007 6:54:57 AM]
Quote:Original post by izzo
Quote:Original post by DrunkenHyena
Also, since everything will now go through a vtable lookup, it will be much less efficient.

Nothing will be going through a vtable lookup, since he hasn't overridden anything.

Mikeske:
If you *really* want to do it this way, you should remove the 'virtual' keyword on the destructor. It adds an unnecessary vtable to your class.

But really, why are you doing this?! You're using the D3DX functions but they're all so basic that you might as well just implement the entire thing yourself. Or if you simply must use them, get rid of the inheritance and add the x, y, and z floats to your own class. Then use a reinterpret_cast to cast the this pointer to a D3DXVECTOR3 when you pass it in to the D3DX functions (for this to work you can't have any virtuals).

As to your link error: check that your project actually is set up as a static library. I've just been setting up a new static library for my own projects in VS 2005 Express and haven't had seen this error. The only thing I can think of is that maybe it's set as a DLL and nothing is marked as exported.

Cheers
Sam


Thx for the support Guys
The solution was even easier then I thought.
The problem disappeared after I moved the #include "math.h" to the cpp file [totally]

To be honest Sam the thing about the reinterpret_cast and such...it's chinese for me, I have a good base of c++ and directx and stuff, but the more profound stuff I'm still noobish [imwithstupid]

About the virtual destructor you're right... It's a nervous tick, when creating a new class to "check" the virtual destructor box [embarrass]

Greetz to all!!!


Hi,

if you don't like the naming convention, why don't you just typedef it then...

typedef D3DXVECTOR3 cVector3;



t0}{!c

This topic is closed to new replies.

Advertisement