简体   繁体   中英

Unresolved external symbol _main referenced

i'm working on an intake assignment for a game development course but i'm stuck with an annoying error by visual studio after splitting my code into classes. The error states LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) So it should be something wrong in my main function. I've looked around and the most logical reason seemt to be wrong subsystem but that's set to console application. Here's my code:

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

Hope anyone can point me in the right direction with what's going wrong :)

Guess i was ignorant... There was a warning about the main.cpp using line endings for Mac Os X since i work on an iMac i didn't care. But when i fixed this in Notepad++ EDIT -> EOL Conversion -> Windows Format , it worked like a sharm! My bad i'm afraid ^^

I solved my problem by the following:

1) closing the project and restarting the PC

2) Creating a new project and following this thread because I was doing GUI http://www.bogotobogo.com/cplusplus/application_visual_studio_2013.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM