I can't figure out where my error is.
I get the message:
Error 21 error LNK2019: unresolved external symbol "public: __thiscall ParticleAnchoredSpring::ParticleAnchoredSpring(class Vector3 *,float,float)" (??0ParticleAnchoredSpring##QAE#PAVVector3##MM#Z) referenced in function "public: void __thiscall MyGameWorld::Initialize(void)" (?Initialize#MyGameWorld##QAEXXZ) C:\Users\Foo Nuts\Dropbox\GSP321_DavidJohnson\GSP321_Johnson_HM2\iLab2\MyGameWorld.obj
function declaration:
ParticleForceRegistry registry;
ParticleAnchoredSpring spring(&Vector3(10, 3, 10), 10, 10);
registry.add(WMI->getListPtr()[0], &spring);
class definition:
class ParticleAnchoredSpring : public ParticleForceGenerator
{
protected:
Vector3 *anchor;
real springConstant, restLength;
public:
ParticleAnchoredSpring(Vector3 *anchor, real springConstant, real restLength);
virtual void updateForce(Particle *particle, real time);
};
constructor declaration:
void ParticleAnchoredSpring::updateForce(Particle *particle, real time)
{
Vector3 force;
particle->getPosition();
force -= *anchor;
real magnitude = force.magnitude();
magnitude = (restLength - magnitude) * springConstant ;
magnitude *= springConstant;
force.normalize();
force *= -magnitude;
particle->addForce(force);
}
You haven't implemented the constructor. You only declared it. Add:
ParticleAnchoredSpring::ParticleAnchoredSpring(Vector3 *_anchor, real _springConstant, real _restLength)
: anchor(_anchor), springConstant(_springConstant), restLength(_restLength)
{
}
to your implementation file.
I'll assume real is defined as float.
Related
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I got 6 unresolved externals. I know what it means but I don't know how to fix it.
Collision.cpp
#include "Collision.h"
void Collision::Collide(Entity &entity1, Entity &entity2)
{
if(entity1.getX() + entity1.getWidth() > entity2.getX() ||
entity1.getX() < entity2.getX() + entity2.getWidth() ||
entity1.getY() + entity1.getHeight() > entity2.getY() ||
entity1.getY() < entity2.getY() + entity2.getHeight())
{
entity1.setX(entity1.getX());
entity1.setY(entity1.getY());
}
}
Collision.h
#ifndef COLLISION_H
#define COLLISION_H
#include "Map.h"
#include "Animation.h"
#include "Entity.h"
class Collision
{
public:
void Collide(Entity &entity1, Entity &entity2);
protected:
Map map;
};
#endif
Where collision is called
collision.Collide(player, enemy);
Entity.h
#ifndef Entity_H
#define Entity_H
#include<SFML/Graphics.hpp>
#include"Animation.h"
#include"Camera.h"
class Entity
{
public:
void Initialize();
void LoadContent();
void Update(sf::RenderWindow &Window);
void Draw(sf::RenderWindow &window);
void setX(float newX);
void setY(float newY);
int getHeight();
int getWidth();
float getX();
float getY();
private:
Camera camera;
float x, y;
int currentFrameX, currentFrameY;
sf::Clock clock;
};
#endif // Entity_H
Unresolved externals
1>Collision.obj : error LNK2019: unresolved external symbol "public: void __thiscall Entity::setX(float)" (?setX#Entity##QAEXM#Z) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide#Collision##QAEXAAVEntity##0#Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: void __thiscall Entity::setY(float)" (?setY#Entity##QAEXM#Z) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide#Collision##QAEXAAVEntity##0#Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: int __thiscall Entity::getHeight(void)" (?getHeight#Entity##QAEHXZ) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide#Collision##QAEXAAVEntity##0#Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: int __thiscall Entity::getWidth(void)" (?getWidth#Entity##QAEHXZ) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide#Collision##QAEXAAVEntity##0#Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: float __thiscall Entity::getX(void)" (?getX#Entity##QAEMXZ) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide#Collision##QAEXAAVEntity##0#Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: float __thiscall Entity::getY(void)" (?getY#Entity##QAEMXZ) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide#Collision##QAEXAAVEntity##0#Z)
Me thinks it's a problem with not overloading the Entity getX() etc. in the Player/Enemy class properly.
It turns out that Entity.cpp has not been included in my project.
Thanks chris and simonc!
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?
I have a LNK error that involves a class A and its derived class B. More precisely, I have this compilation error
Error 239 error LNK2019: unresolved external symbol "public: virtual __thiscall A::~A(void)" (??1A##UAE#XZ) referenced in function "public: virtual __thiscall B::~B(void)" (??1B##UAE#XZ) D:\Products\path\file.lib(B.obj)
Error 240 error LNK2019: unresolved external symbol "public: __thiscall A::A(void)" (??A##QAE#XZ) referenced in function "public: __thiscall B::B(void)" (??B##QAE#XZ) D:\Products\path\file.lib(B.obj)
Error 241 error LNK2019: unresolved external symbol "public: void __thiscall A::function(float * *,float * *,float * *,float * *,int)" (?function#A##QAEXPAPAM000H#Z) referenced in function "public: class SomeType* __thiscall B::function_bis(void)" (?function_bis#B##QAEPAVSomeType##XZ) D:\Products\path\file.lib(B.obj)
I guess this may be related to, say, call of inherited constructor, or the non-respect of the signature in some call of function() or function_bis(). However, such mistakes i cannot find.
Do you have a hint to a possible way to solve ? Here is code for (simplified) A and B.
B.cpp
B::B(void)
{
}
B::B(Type1* d1, Type1* d2, Type1* r):A()
{
D1= d1;
D2= d2;
R= r;
}
B::~B( void )
{
}
SomeType* B::function()
{
// do things
function_bis() ;
}
B.h
class B:
public A
{
public:
B(void) ;
B(Type1* , Type1* , Type1* );
virtual ~B(void);
SomeType* function() ;
private:
Type1* D1;
Type1* D2;
Type1* R;
};
A.cpp
using namespace std ;
A::A(void){}
A::~A(void){}
void A::function_bis(float** d, float** d2, float** d3, float** d4, int n)
{}
A.h
class A
{
public:
A(void);
virtual ~A(void);
void function_bis(float** , float** , float** , float** , int );
};
Thanks!
Everything looks legit in your code.
My guess is that you actually don't compile A.cpp or somehow you don't include the resulting object file in your linking step (you miss A::A, A::~A and A::function_bis which are defined in A.cpp).
1>main.obj : error LNK2019: unresolved external symbol "public: virtual bool __thiscall LinkedSortedList<int>::getfirst(int &)" (?getfirst#?$LinkedSortedList#H##UAE_NAAH#Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall LinkedSortedList<int>::clear(void)" (?clear#?$LinkedSortedList#H##UAEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall LinkedSortedList<int>::print(void)const " (?print#?$LinkedSortedList#H##UBEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: virtual bool __thiscall LinkedSortedList<int>::insert(int)" (?insert#?$LinkedSortedList#H##UAE_NH#Z) referenced in function _main
1>main.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall LinkedSortedList<int>::find(int)const " (?find#?$LinkedSortedList#H##UBE_NH#Z)
1>main.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall LinkedSortedList<int>::size(void)const " (?size#?$LinkedSortedList#H##UBEHXZ)
1>c:\users\chris\documents\visual studio 2010\Projects\lab0\Debug\lab0.exe : fatal error LNK1120: 6 unresolved externals
This is what I recieve when trying to compile my code. I've narrowed it down to (i believe) this section of code here:
#ifndef _LinkedSortedListClass_
#define _LinkedSortedListClass_
#include "LinkedNode.h"
#include "SortedList.h"
template <class Elm>
class LinkedSortedList: public SortedList<int> {
public:
void clear();
bool insert(Elm newvalue);
bool getfirst(Elm &returnvalue);
void print() const;
bool find(Elm searchvalue) const;
int size() const;
private:
LinkedNode<Elm>* head;
};
#endif
This is the child class of the SortedList, which is this, in case it's needed..
#ifndef _SortedListClass_
#define _SortedListClass_
template <class Elm> class SortedList {
public:
// -------------------------------------------------------------------
// Pure virtual functions -- you must implement each of the following
// functions in your implementation:
// -------------------------------------------------------------------
// Clear the list. Free any dynamic storage.
virtual void clear() = 0;
// Insert a value into the list. Return true if successful, false
// if failure.
virtual bool insert(Elm newvalue) = 0;
// Get AND DELETE the first element of the list, placing it into the
// return variable "value". If the list is empty, return false, otherwise
// return true.
virtual bool getfirst(Elm &returnvalue) = 0;
// Print out the entire list to cout. Print an appropriate message
// if the list is empty. Note: the "const" keyword indicates that
// this function cannot change the contents of the list.
virtual void print() const = 0;
// Check to see if "value" is in the list. If it is found in the list,
// return true, otherwise return false. Like print(), this function is
// declared with the "const" keyword, and so cannot change the contents
// of the list.
virtual bool find(Elm searchvalue) const = 0;
// Return the number of items in the list
virtual int size() const = 0;
};
#endif
Thanks so much for any help; our last class taught us nothing of inheritance, but this is project #1 for this class, without being taught inheritance here either, so this is all touch and go for me, despite what I managed to look up on Google.
Your methods aren't defined. So the linker is complaining because it can't link to their definitions.
Maybe it helps if you placed the definitions of your functions in your header file. This makes it easier for the compiler to resolve these external symbols.
I hope this will help.
Regards,
Philinator
#include <iostream>
using namespace std;
class A {
public:
void function( int num);
bool function1()const;
virtual bool function2() const=0;
};
class B:public A {
public :
bool function2()const;
};
int _tmain(int argc, _TCHAR* argv[])
{
void (A::* p)(int)= &A::function; //不是地址,而是一个指向成员函数的指针
// Edit: Google translation of the above comment is
// "Not address, but a pointer to a member function pointer"
bool (A::* p1)()const =&A::function1; // 指向成员函数的指针可以指向一个常量成员函数
// Edit: Google translation of the above comment is
// "Point to a member function pointer can point to a const member function"
B b;
A *a=&b;
(a->*p1)();
(b.*p1)();
return 0;
}
but when I link it:
1>c.obj : error LNK2019: unresolved external symbol "public: bool __thiscall A::function1(void)const " (?function1#A##QBE_NXZ) referenced in function _wmain
1>c.obj : error LNK2019: unresolved external symbol "public: void __thiscall A::function(int)" (?function#A##QAEXH#Z) referenced in function _wmain
1>c.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall B::function2(void)const " (?function2#B##UBE_NXZ)
can you tell me why?
You haven't implemented A::function(), A::function1(), or B::function2(). You need to do that.
A::function1, A::function and B::function2 are all declared, but never defined. You can't get a pointer to the function if it is not defined, where would it point?
Code
#include <OOLua/oolua.h>
class foo
{
public:
int bar();
};
OOLUA_CLASS_NO_BASES(foo)//class has no bases
OOLUA_NO_TYPEDEFS
OOLUA_MEM_FUNC_0(int,bar)
OOLUA_CLASS_END
void test()
{
OOLUA::Script s;
s.register_class<foo>();
}
Compiler output
1>main.obj : error LNK2001: unresolved external symbol "public: static struct OOLUA::Proxy_class<class foo>::Reg_type_const * OOLUA::Proxy_class<class foo>::class_methods_const" (?class_methods_const#?$Proxy_class#Vfoo###OOLUA##2PAUReg_type_const#12#A)
1>main.obj : error LNK2001: unresolved external symbol "public: static struct OOLUA::Proxy_class<class foo>::Reg_type * OOLUA::Proxy_class<class foo>::class_methods" (?class_methods#?$Proxy_class#Vfoo###OOLUA##2PAUReg_type#12#A)
1>main.obj : error LNK2001: unresolved external symbol "public: static char const * const OOLUA::Proxy_class<class foo>::class_name" (?class_name#?$Proxy_class#Vfoo###OOLUA##2QBDB)
1>main.obj : error LNK2001: unresolved external symbol "public: static char const * const OOLUA::Proxy_class<class foo>::class_name_const" (?class_name_const#?$Proxy_class#Vfoo###OOLUA##2QBDB)
1>main.obj : error LNK2001: unresolved external symbol "public: static int const OOLUA::Proxy_class<class foo>::name_size" (?name_size#?$Proxy_class#Vfoo###OOLUA##2HB)
Using
Visual Studio 2008
OOLua 1.2.1
(OOLua .lib has been built and linked to)
(OOLua solution via premake 3 with test.unit and profile projects removed)
(OOLua obtained via SVN -> trunk | Jan 3rd)
Links
http://code.google.com/p/oolua/
OOLua compile errors
Question
How can it be fixed?
Solution
class foo
{
public:
int bar()
{
return 0;
}
};
OOLUA_CLASS_NO_BASES(foo)//class has no bases
OOLUA_NO_TYPEDEFS
OOLUA_MEM_FUNC_0(int,bar)
OOLUA_CLASS_END
EXPORT_OOLUA_FUNCTIONS_1_NON_CONST(foo /*name of class*/
,bar)/*function being exposed*/
EXPORT_OOLUA_FUNCTIONS_0_CONST(foo)
void test()
{
OOLUA::Script s;
s.register_class<foo>();
}
http://code.google.com/p/oolua/wiki/CheatSheet#Has_a_member_function_which_takes_no_parameters
Then in a source file expose the class
telling the framework that the
instance has a function of interest
yet no constant member functions, also
providing the name it will be
identified by in Lua code(foo).
EXPORT_OOLUA_FUNCTIONS_1_NON_CONST(foo /*name of class*/
,bar)/*function being exposed*/
EXPORT_OOLUA_FUNCTIONS_0_CONST(foo)