【问题标题】:Unresolved external symbol _main referenced未解析的外部符号 _main 引用
【发布时间】:2016-04-29 12:52:19
【问题描述】:

我正在为一个游戏开发课程做一个摄入分配,但是在将我的代码分成类之后,我遇到了 Visual Studio 的一个恼人的错误。错误状态LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 所以它应该是我的主要功能有问题。我环顾四周,最合乎逻辑的原因似乎是错误的子系统,但它设置为控制台应用程序。这是我的代码:

Main.cpp:

#include <Box2D/Box2D.h>
#include <SFML/Graphics.hpp>

#include "Game.hpp"

int main() {
    Game game; //Sets up the game

    game.populateWorld();

    while (game.window.isOpen()) {
        game.checkEvents();

        game.drawBodies();

        game.m_Player->movePlayer();

    }

    return 0;
}

Game.hpp:

#ifndef Game_hpp
#define Game_hpp

#include <SFML/Graphics.hpp>
#include "World.hpp" 
#include "Player.hpp"
class Game {
public:
    Game();
    void checkEvents();
    void drawBodies();//Displays the bodies and keeps the view centered

    //Public data members to be used by other classes
    sf::Texture backGroundTexture;
    sf::Texture playerTex;
    sf::Texture platformTex;//Doesn't have a sprite declared since multiple copy's will be made
    sf::Sprite backGround;
    sf::Sprite player;
    sf::View view;
    sf::RenderWindow window;

    const float m_Scale;//Number of pixels per meter

    Player* m_Player = NULL;
    World* m_World = NULL;
    void populateWorld();
private:
    void loadResources();//Loads resources and applies them where needed
};
#endif // !Game_hpp

World.hpp:

#ifndef World_hpp
#define World_hpp

#include <Box2D/Box2D.h>

class World {
public:
//Public member functions
    World(const float scale);
    ~World();
    void step();
    b2Body* spawnPlayer(float x, float y);

//Public data members
    b2World* world = NULL; //Points to the entire world! Handle with care ;)

    void createPlatform(b2Vec2 point);
private:
//Private data members
    b2Vec2 gravity;
    const float m_Scale;

    //Declaring step values
    float32 m_TimeStep;
    int32 m_VelocityIterators;
    int32 m_PositionIterators;
};

#endif // !World_hpp

Player.hpp:

#ifndef Player_hpp
#define Player_hpp

#include <Box2D/Box2D.h>

#include "World.hpp"

class Player{

public:
    Player(World* world, const float scale, float x, float y);
    void movePlayer();
    b2Body* m_PlayerBody;//A pointer to the player Character's body needed      for the movement
private:
    World* m_World;
    const float m_Scale;
};

#endif // !Player_hpp

希望任何人都可以指出错误的正确方向:)

【问题讨论】:

标签: c++ visual-studio box2d sfml


【解决方案1】:

猜我是无知的...有一个警告关于 main.cpp 使用 Mac Os X 的行尾,因为我在 iMac 上工作,我不在乎。但是当我在 Notepad++ EDIT -&gt; EOL Conversion -&gt; Windows Format 中修复这个问题时,它就像一个 sharm!我的坏我害怕^^

【讨论】:

    【解决方案2】:

    我通过以下方式解决了我的问题:

    1) 关闭项目并重启电脑

    2) 创建一个新项目并关注这个线程,因为我正在做 GUI http://www.bogotobogo.com/cplusplus/application_visual_studio_2013.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 2015-05-04
      • 1970-01-01
      • 1970-01-01
      • 2012-06-30
      相关资源
      最近更新 更多