0

So I'm making a game, and it was working perfectly fine, so I started developing the next part of the game which is the chunking system and the generation (you might be able to tell from my previous posts) but then all of a sudden I got some random linker errors, even though I haven't touched anything in the linker and the game was working perfectly fine before. Here are the errors:

Error   3   error LNK2019: unresolved external symbol "public: class sf::Sprite __thiscall AbstractBlock::draw(void)" (?draw@AbstractBlock@@QAE?AVSprite@sf@@XZ) referenced in function _main   C:\(Insert personal stuff here)\Main.obj    Top Down Shooter
Error   4   error LNK2019: unresolved external symbol "public: void __thiscall AbstractBlock::destroy(class b2World *)" (?destroy@AbstractBlock@@QAEXPAVb2World@@@Z) referenced in function "public: int __thiscall Universe::saveGame(void)" (?saveGame@Universe@@QAEHXZ)  C:\(Insert personal stuff here)\Universe.obj    Top Down Shooter
Error   5   error LNK1120: 2 unresolved externals

They don't have line numbers and it appears the problem is in the Universe.obj and main.obj? I honestly don't know what those are, so instead I'm going to post both of the .cpp files in full:

Universe.cpp:

#include "Universe.h"

Universe::Universe(){

    world = new b2World(b2Vec2(0, 0));
    world->SetAllowSleeping(false);

    chunkManager = new ChunkManager(world);

    player = new Player(world);


}


Universe::~Universe()
{
}

int Universe::saveGame(){
    player->destroy(world);
    player = nullptr;


    std::list<AbstractBlock>::iterator i;

    for (i = getLoadedBlocks()->begin(); i != getLoadedBlocks()->end(); i++){
        i->destroy(world);
    }

    world = nullptr;
    return 1;
}

void Universe::spawnEntity(int x, int y, int entityID){

}

std::list<AbstractBlock>* Universe::getLoadedBlocks(){
    return chunkManager->getLoadedBlocks();
}

void Universe::update(){

    player->update();

    world->Step(1 / 60.f, 8, 3);
}

Player* Universe::getPlayer(){
    return player;
}

Main.cpp:

#include <iostream>
#include "Box2D\Box2D.h"
#include "SFML/Graphics.hpp"
#include "Universe.h"
#include "simplexnoise.h"

int main(){

    static int FPS = 1.f / 60.f;

    sf::RenderWindow window(sf::VideoMode(640, 480), "Top Down Shooter");
    sf::Event event;

    Universe universe;

    bool running = true;
    int distX;
    int distY;
    float angle;

    while (running){

        window.clear(sf::Color::White);

        while (window.pollEvent(event)){
            switch (event.type){
            case sf::Event::Closed:
                running = false;
                break;
            case sf::Event::KeyPressed:
                switch (event.key.code){
                case sf::Keyboard::Q:
                    running = false;
                    break;
                case sf::Keyboard::W:
                    universe.getPlayer()->setMoveUp(true);
                    break;
                case sf::Keyboard::A:
                    universe.getPlayer()->setMoveLeft(true);
                    break;
                case sf::Keyboard::D:
                    universe.getPlayer()->setMoveRight(true);
                    break;
                case sf::Keyboard::S:
                    universe.getPlayer()->setMoveDown(true);
                    break;
                }
                break;
            case sf::Event::KeyReleased:
                switch (event.key.code){
                case sf::Keyboard::W:
                    universe.getPlayer()->setMoveUp(false);
                    break;
                case sf::Keyboard::A:
                    universe.getPlayer()->setMoveLeft(false);
                    break;
                case sf::Keyboard::D:
                    universe.getPlayer()->setMoveRight(false);
                    break;
                case sf::Keyboard::S:
                    universe.getPlayer()->setMoveDown(false);
                    break;
                }
                break;

            }


        }

        distX = (sf::Mouse::getPosition().x - universe.getPlayer()->getXpos() - window.getPosition().x - 10);
        distY = (sf::Mouse::getPosition().y - universe.getPlayer()->getYpos() - window.getPosition().y - 30);
        if (distX != 0){
            angle = std::atan2f(distY, distX);
            universe.getPlayer()->setAngle(angle + (b2_pi / 2));
        }

        //Updating the universe
        universe.update();

        //Drawing Everything
        window.draw(universe.getPlayer()->draw());

        std::list<AbstractBlock>::iterator i;

        for (i = universe.getLoadedBlocks()->begin(); i != universe.getLoadedBlocks()->end(); i++){
            window.draw(i->draw());
        }




        window.display();


    }

    universe.saveGame();

    return 0;
}

So I was trying to figure out the problem on my own, and I thought it may have been the part where I use the iterator and the lists to draw all the current blocks in the universe. I thought this because both the Universe and main .cpp have these small for loops in them (which I just recently added). So I commented out those parts in each file and things got even weirder. Visual Studio 2013 then gave me errors when I ran my program and then would take me to xutility file! I have no idea why! I made sure to comment out the iterator part and tried again but the same thing happened! With those two lines of iterators commented out I'm not using iterators at all in my program! Why would it be taking me to there? Please help i'm so confused >.<

Edit: AbstractBlock.cpp:

#include "AbstractBlock.h"


AbstractBlock::AbstractBlock()
{
}

AbstractBlock::AbstractBlock(int x, int y, float roation, b2World *world){

}

sf::Sprite AbstractBlock::draw(){
    sf::Sprite sprite;
    return sprite;
}

void AbstractBlock::destroy(b2World *world){

}


AbstractBlock::~AbstractBlock()
{
}

I'm originally a Java programmer, and I wasn't sure if there was a way to make an "abstract" class like you can in Java, so instead I just made a normal class with not to many defined methods, which is then inherited by other classes.

Second Edit: I have also decided to show my Dirt class which extends my AbstracBlock class and so far is the only class that inherits from AbstractBlock:

#include "DirtBlock.h"


DirtBlock::DirtBlock()
{
}

DirtBlock::DirtBlock(int x, int y, float rotation, b2World *world){
    bodyDef.position.Set(x, y);
    bodyDef.type = b2_dynamicBody;

    fixDef.density = .1f;

    b2PolygonShape shape;
    shape.SetAsBox(16, 16);

    fixDef.shape = &shape;

    body = world->CreateBody(&bodyDef);
    body->CreateFixture(&fixDef);

    texture.loadFromFile("dirt.png");

}

void DirtBlock::destroy(b2World *world){
    world->DestroyBody(body);
    body = nullptr;
}


DirtBlock::~DirtBlock()
{
}

sf::Sprite DirtBlock::draw(){
    sf::Sprite sprite;
    sprite.setTexture(texture);
    sprite.setOrigin(16, 16);
    sprite.setPosition(body->GetPosition().x, body->GetPosition().y);
    return sprite;
}

Third Edit: Also! This is where VisualStudio takes me when I try to run my program:

 #if _ITERATOR_DEBUG_LEVEL == 2
            if (_Myproxy != _Parent_proxy)
                {   // change parentage
                _Lockit _Lock(_LOCK_DEBUG);
                _Orphan_me();
                _Mynextiter = _Parent_proxy->_Myfirstiter;
                _Parent_proxy->_Myfirstiter = this;
                _Myproxy = _Parent_proxy;
                }

It's located in the xutility class and I have no idea what this is.The next line to be performed is the _Mynextiter line.

MagnusCaligo
  • 707
  • 2
  • 8
  • 28
  • The problem is not in these files. The problem is in the file(s) that defines `AbstractBlock::draw(void)` and `AbstractBlock::destroy(class b2World *)`. This file(s) is missing from the project (or the definitions are missing from the file), which is why these definitions are not found by the linker. – AnT stands with Russia Jul 02 '15 at 04:48
  • Is `AbstractBlock` a library object? If not show us the files defining it, and make sure to include its header in Main.cpp – Karthik T Jul 02 '15 at 04:49
  • Things also just got a bit more weird... You know how I said the Visual Studio would gave me an error and take me to the xutility file when I had the iteration part commented out? Well I uncommented it but now it still takes me there O.O i'm so confused – MagnusCaligo Jul 02 '15 at 04:55
  • @MagnusCaligo: Er.. What? You stated in your question that you get linker errors. Now you added a part that says that you can "run your program". This does not make any sense. It is not possible to run a program that does not compile (e.g. reports linker errors). So, does your program compile or not? – AnT stands with Russia Jul 02 '15 at 05:18
  • @AnT it's compiling now! I don't know why! But now the program is stopped by Visual Studio and give me some strange error. I made a second question covering exactly this: http://stackoverflow.com/questions/31176092/unhandled-exception-at-0x000fba44-in-top-down-shooter ....I honestly am so confused and might go to bed and figure this out tomorrow XD – MagnusCaligo Jul 02 '15 at 05:19

1 Answers1

0

Well, the immediate guess would be that you simply forgot to add your AbstractBlock.cpp to your project.

AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765
  • It is added to the project. I used to Visual Studio to make it in the project. I didn't transfer it over from anywhere – MagnusCaligo Jul 02 '15 at 04:56
  • @MagnusCaligo: When you build your project from scatch, Visual Studio gives you the names of the files it compiles in the Build window. Do you see `AbstractBlock.cpp` in that list? – AnT stands with Russia Jul 02 '15 at 04:57
  • I just rebuilt the project and yes I see the AbstractBlock.cpp class in the list.... I don't know why, but I have a feeling VS might be freaking out... I'm going to close it and reopen to see if that does anything – MagnusCaligo Jul 02 '15 at 05:00
  • Nope that did nothing :/ – MagnusCaligo Jul 02 '15 at 05:00
  • @MagnusCaligo: Er.. What? You stated in your question that you get linker errors. Now you added a part that says that you can "run your program". This does not make any sense. It is not possible to run a program that does not compile (e.g. reports linker errors). So, does your program compile or not? – AnT stands with Russia Jul 02 '15 at 05:18