linking problems in VC++ 6 - LNK2001
I keep getting the same error all the time, just can''t figure out whats going wrong. Its a LNK2001 error. Can anyone offer any suggestions whats going wrong?
Any help would be MUCH APPRECIATED!!
Thanks in advance
- Pete
Linking...
intersect.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CVector::~CVector(void)" (??1CVector@@UAE@XZ)
Plane.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CVector::~CVector(void)" (??1CVector@@UAE@XZ)
intersect.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CPlane::LineIntersect(class CVector &,class CVector &,class CVector &,class CVector &)" (?LineIntersect@CPlane@@QAE_NAAVCVector@@000@Z)
Debug/intersect.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
Creating browse info file...
I''ll post some code if it would help, but there is quite a lot.
The error means that you''re calling a function that it can''t find a body for. Specifically, you declare a destructor for CVector, but don''t define it, and you must not have LineIntersect defined either.
I''m assuming CVector is derived from something else...
According to my C++ primer, if you''re inheriting from a class with one or more virtual functions, the base class destructor should be virtual as well... you might want to try that. And when you make the virtual base class destructor, remember you should make a CVector destructor as well (it is assumed to be virtual, you simply declare ~CVector() not virtual ~CVector()). Also, make sure you''re not trying to delete an object of the derived class using a pointer of type base class, if the base class has a protected destructor.
If none of this helps, try posting a small amount of code that should compile but doesn''t and I''ll havea look at it.
According to my C++ primer, if you''re inheriting from a class with one or more virtual functions, the base class destructor should be virtual as well... you might want to try that. And when you make the virtual base class destructor, remember you should make a CVector destructor as well (it is assumed to be virtual, you simply declare ~CVector() not virtual ~CVector()). Also, make sure you''re not trying to delete an object of the derived class using a pointer of type base class, if the base class has a protected destructor.
If none of this helps, try posting a small amount of code that should compile but doesn''t and I''ll havea look at it.
C:\3D ENGINE - MY\intersect\intersect.cpp(15) : warning C4700: local variable ''plane'' used without having been initialized
Linking...
intersect.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CPlane::LineIntersect(class CVector &,class CVector &,class CVector &,class CVector &)" (?LineIntersect@CPlane@@QAE_NAAVCVector@@000@Z)
Debug/intersect.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Hello
Thanks everyone for their current suggestions, but I still can''t get it to work. Ive pasted a simplified section of code. As you can see, I create a vector then create an instance of CPlane. I then call the method LineIntersect, but it has linking problems. But, this method does exist and is implemented in the .cpp file. I''ve included the relevant header files, so I can''t see the problem. Does anyone have any ideas?
As i said before, any help is much appreciated
- Thanks in advance
Pete
####################### Main Program ########################
#include "stdafx.h"
#include <iostream.h>
#include "Vector.h"
#include "Plane.h"
void main(int argc, char* argv[])
{
CVector vec(2.0, 2.0, 2.0);
CPlane* plane;
plane->LineIntersect(vec, vec, vec, vec);
}
#############################################################
########### Plane.h: ########################################
#if !defined(AFX_PLANE_H__BD619804_EDD2_4CA7_849D_5472453C1712__INCLUDED_)
#define AFX_PLANE_H__BD619804_EDD2_4CA7_849D_5472453C1712__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
static const float Epsilon = 1.0e-05f;
#include "Vector.h"
class CPlane
{
public:
CPlane();
virtual ~CPlane();
inline bool LineIntersect(CVector &start, CVector &end, CVector &point, CVector &result);
//protected:
CVector n;
float d;
};
#endif // !defined(AFX_PLANE_H__BD619804_EDD2_4CA7_849D_5472453C1712__INCLUDED_)
##########################################################
###################### Plane.cpp #########################
#include "stdafx.h"
#include "Plane.h"
CPlane::CPlane()
{
}
CPlane::~CPlane()
{
}
inline bool CPlane::LineIntersect(CVector &start, CVector &end, CVector &point, CVector &result)
{
float denom, numer, u;
CVector dir;
dir = end - start;
denom = n.Dot(dir);
if (denom > -Epsilon && denom < Epsilon) // No divide by zero!
return 0; // Line is parallel to the plane
numer = n.Dot(point - start);
u = numer / denom;
if (u <= 0.0f || u > 1.0f) // Is there an intersection along the line?
return 0;
result = start + dir * u;
return 1;
}
#############################################################
If you create a pointer of a class then you must use the keyword "new"
CPlane *plane = new CPlane;
plane->LineIntersect(vars);
otherwise a pointer to any variable is still just a long with a pointer of value of null.
Edited by - afterburn on March 6, 2002 8:58:06 PM
CPlane *plane = new CPlane;
plane->LineIntersect(vars);
otherwise a pointer to any variable is still just a long with a pointer of value of null.
Edited by - afterburn on March 6, 2002 8:58:06 PM
--What are you nutz?I have nothing to say to your unevolved little brain. The more I say gives you more weapons to ask stupid questions.
yes that''s an error in main(), it''s not the compile-time error the poster was trying to figure out, however.
I have eventually figured out how to get rid of the linking error but not sure why. I changed the definition of
inline bool CPlane::LineIntersect(CVector start, CVector end, CVector point, CVector result)
to
bool CPlane::LineIntersect(CVector start, CVector end, CVector point, CVector result)
(just got rid of inline) in the header and implementation, and now it works! But why would this have caused a linking problem?
Just one further question, THANKYOU ''afterburn'' for picking up on an error in my code. But could someone explain the advantages of using a pointer of a class, such as
CPlane *plane = new CPlane;
plane->LineIntersect(vars);
rather than just
CPlane plane
plane.LineIntersect(vars);
They both work fine in this instance, so why the extra work? I have a rough idea of pointers but cant grasp the advantages in this case.
This is the code for vector.h code as requested, but this works fine.
// Vector.h: interface for the CVector class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_VECTOR_H__D2279054_5C30_4487_B062_57C49C99F868__INCLUDED_)
#define AFX_VECTOR_H__D2279054_5C30_4487_B062_57C49C99F868__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CVector
{
public:
CVector() {v[0] = v[1] = v[2] = 0;}
CVector(float px, float py, float pz) {v[0]=px; v[1] = py; v[2] = pz;}
CVector(const CVector &pVec) {v[0]=pVec.v[0]; v[1] = pVec.v[1]; v[2] = pVec.v[2];}
CVector(const float *pVec) {v[0]=pVec[0]; v[1] = pVec[1]; v[2] = pVec[2]; }
virtual ~CVector() {}
CVector operator+(const CVector &pVec) {return CVector(v[0] + pVec.v[0], v[1] + pVec.v[1], v[2] + pVec.v[2]);}
CVector operator-(const CVector &pVec) {return CVector(v[0] - pVec.v[0], v[1] - pVec.v[1], v[2] - pVec.v[2]);}
CVector operator*(float val) {return CVector(v[0] * val, v[1] * val, v[2] * val);}
float Dot(const CVector &pVec) {return v[0] * pVec.v[0] + v[1] * pVec.v[1] + v[2] * pVec.v[2];}
float v[3];
};
#endif // !defined(AFX_VECTOR_H__D2279054_5C30_4487_B062_57C49C99F868__INCLUDED_)
March 07, 2002 09:32 AM
Because the function body for an ''inline'' class method is supposed to be in the body of the class.
You probably shouldn''t have been inlining that anyway.
You probably shouldn''t have been inlining that anyway.
Anonymous says;
but as far as I know this is totally wrong.. if you put your code in the class body then you don't need to use inline keyword anyways.. I use inline almost everywhere and they seem to work (never checked the asm code produced though) by the way, as far as I remember, MSVC standard edition cannot inline!!! If you install service packs, it can though..
about csxpcm's question on;
for your specific case, yes they are simply the same things. But with pointers you have more control about the lifetime of your object. you can always call delete to destroy it, or better, pass the same instance of your object to other parts of your program. I would suggest not to worry about these confusions, in the beginning I hated pointers (was a pascal guy b4) but now, I just love them.. you will get the idea as you program..
cheers..
-----------
my quote is under construction
Edited by - mentat on March 7, 2002 10:51:10 AM
quote:
Because the function body for an 'inline' class method is supposed to be in the body of the class.
but as far as I know this is totally wrong.. if you put your code in the class body then you don't need to use inline keyword anyways.. I use inline almost everywhere and they seem to work (never checked the asm code produced though) by the way, as far as I remember, MSVC standard edition cannot inline!!! If you install service packs, it can though..
about csxpcm's question on;
quote:
They both work fine in this instance, so why the extra work? I have a rough idea of pointers but
cant grasp the advantages in this case.
for your specific case, yes they are simply the same things. But with pointers you have more control about the lifetime of your object. you can always call delete to destroy it, or better, pass the same instance of your object to other parts of your program. I would suggest not to worry about these confusions, in the beginning I hated pointers (was a pascal guy b4) but now, I just love them.. you will get the idea as you program..
cheers..
-----------
my quote is under construction
Edited by - mentat on March 7, 2002 10:51:10 AM
-----------my quote is under construction
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement