链接器错误2019而没有触及链接器属性?

时间:2015-07-02 04:46:11

标签: c++ linker

所以我正在制作游戏,而且它的工作非常好,所以我开始开发游戏的下一部分,即分块系统和代(你可以从我以前的帖子中说出来)但是突然之间我得到了一些随机的链接器错误,即使我没有触及链接器中的任何东西,并且之前游戏运行得非常好。以下是错误:

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

他们没有行号,看来问题出现在Universe.obj和main.obj中?老实说,我不知道那些是什么,所以我要完全发布两个.cpp文件:

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;
}

所以我试图自己解决问题,我认为它可能是我使用迭代器和列表来绘制宇宙中所有当前块的部分。我认为这是因为Universe和main .cpp都有这些小的for循环(我刚刚添加)。所以我在每个文件中注释掉了那些部分,事情变得更加怪异了。 Visual Studio 2013然后在我运行程序时给了我错误,然后将我带到xutility文件!我不知道为什么!我确定要注释迭代器部分并再试一次,但同样的事情发生了!有了这两行迭代器注释掉我在我的程序中根本没有使用迭代器!为什么要带我去那里?请帮助我这么困惑&gt;。&lt;

编辑: 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()
{
}

我原来是一名Java程序员,而且我不确定是否有办法制作一个&#34;抽象&#34;你可以在Java中使用类,所以我只使用了很多定义的方法创建了一个普通的类,然后由其他类继承。

Second Edit:我还决定展示我的Dirt类,它扩展了我的AbstracBlock类,到目前为止是继承自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;
}

第三编辑:还!这是VisualStudio在我尝试运行程序时带我的地方:

 #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;
                }

它位于xutility类中,我不知道它是什么。下一行要执行的是_Mynextiter行。

1 个答案:

答案 0 :(得分:0)

嗯,立即猜测你只是忘了将AbstractBlock.cpp添加到你的项目中。