Why am I getting linker errors when I split my program into separate files?
Apr 5, 2015 at 4:19pm UTC
The error I'm getting:
LNK2001: ' unresolved external symbol "public: __cdecl Object::Object(void)" (??0Object@@QEAA@XZ)
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
//Object.h
#ifndef OBJECT_H
#define OBJECT_H
#include <SFML/Graphics.hpp>
using namespace sf;
class Object
{
public :
RectangleShape rect;
Object();
Object(Vector2f position, Vector2f size, Color color);
void Update();
bool Collision(Object p);
float bottom, top, left, right;
};
#endif
//Object.cpp
#include <SFML/Graphics.hpp>
#include "Object.h"
using namespace sf;
Object::Object(Vector2f position, Vector2f size, Color color) //Constructor converts paramaters to variables
{
rect.setPosition(position);
rect.setSize(size);
rect.setFillColor(color);
}
void Object::Update()
{
bottom = rect.getPosition().y + rect.getSize().y;
top = rect.getPosition().y;
right = rect.getPosition().x + rect.getSize().x;
left = rect.getPosition().x;
}
bool Object::Collision(Object p)
{
if (right < p.left || left > p.right || top > p.bottom || bottom < p.top)
{
return false ;
}
return true ;
}
//Block.h
#ifndef BLOCK_H
#define BLOCK_H
#include <SFML/Graphics.hpp>
#include "Object.h"
using namespace sf;
class Block : public Object
{
public :
Block();
Block(Vector2f position, Color color);
};
#endif
//Block.cpp
#include <SFML/Graphics.hpp>
#include "Block.h"
#include "Object.h"
using namespace sf;
Block::Block()
{
rect.setPosition(0, 0);
rect.setSize(Vector2f(64, 64));
rect.setFillColor(Color::Red);
}
Block::Block(Vector2f position, Color color)
{
rect.setPosition(position);
rect.setSize(Vector2f(64, 64));
rect.setFillColor(color);
}
I know I've properly statically linked SFML (The graphics library I'm using) because when I commented out every single file and ran some example SFML code it worked. Also, if it is important, I am compiling 64 bit code.
Last edited on Apr 5, 2015 at 4:23pm UTC
Apr 5, 2015 at 4:33pm UTC
1 2 3 4 5 6 7 8
public :
RectangleShape rect;
Object(); // try changing this to object(){}
Object(Vector2f position, Vector2f size, Color color);
void Update();
bool Collision(Object p);
float bottom, top, left, right;
};
Apr 5, 2015 at 4:37pm UTC
I have absolutely no idea why that works but it does! Thank you so much :D
Apr 5, 2015 at 4:45pm UTC
If you
google unresolved external symbol c++
you might find out :p
Topic archived. No new replies allowed.