ОШИБКИ:
Код: Выделить всё
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.o:main.cpp:(.text+0x18): undefined reference to `Game::Game()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.o:main.cpp:(.text+0x26): undefined reference to `Game::update()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.o:main.cpp:(.text+0x32): undefined reference to `Game::render()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.o:main.cpp:(.text+0x3e): undefined reference to `Game::running() const'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.o:main.cpp:(.text+0x53): undefined reference to `Game::~Game()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.o:main.cpp:(.text+0x66): undefined reference to `Game::~Game()'
collect2.exe: error: ld returned 1 exit status
Код: Выделить всё
#include
#include "include\Game.hpp"
int main()
{
// Start game engine
Game game;
// run the program as long as the window is open
while (game.running())
{
// Update
game.update();
// Render
game.render();
}
return 0;
}
Код: Выделить всё
#pragma once
#include
#include
#include
#include
#include
/*
This class acts as the game engine???
Wrapper class????
*/
class Game {
public:
// Constructor + Destructor
Game();
virtual ~Game();
// Accessors
const bool running() const;
// Functions
void pollEvents();
void update();
void render();
private:
// Variables
// Window
sf::RenderWindow* window;
sf::VideoMode videoMode;
sf::Event event;
// Functions (Private)
void initializeVariables();
void initWindow();
};
Код: Выделить всё
#include "include\Game.hpp"
// Constructor
Game::Game()
{
this->initializeVariables();
this->initWindow();
}
// Deconstructor
Game::~Game()
{
delete this->window;
}
// Accessors
// Uses SFML function "isOpen()" to make a bool to be used in main while loop
const bool Game::running() const
{
return this->window->isOpen();
}
// Functions (Public)
void Game::pollEvents()
{
// Event polling
while (this->window->pollEvent(this->event))
{
switch (this->event.type)
{
case sf::Event::Closed:
this->window->close();
break;
case sf::Event::KeyPressed:
if (this->event.key.code == sf::Keyboard::Escape)
{
this->window->close();
break;
}
break;
default:
break;
}
}
}
void Game::update()
{
this->pollEvents();
}
void Game::render()
{
/*
This function renders (draws) everything to the screen
1. Clear
2. Render
3. Display
*/
// "And the lord said: ALWAYS CLEAR BEFORE DISPLAY!" | SFML 11:37
this->window->clear(sf::Color::White);
// Draw gameobjects
this->window->display();
}
// Functions (Private)
// Initilize pointers from "Game.hpp"
void Game::initializeVariables()
{
this->window = nullptr;
}
// Initilize window
void Game::initWindow()
{
this->videoMode.height = 1280;
this->videoMode.width = 720;
this-> window = new sf::RenderWindow(this->videoMode, "Application #1", sf::Style::Close | sf::Style::Titlebar);
}
При создании файла .exe из .o терминал выдал кучу ошибок, касающихся «Неопределенных ссылок».
Подробнее здесь: https://stackoverflow.com/questions/782 ... c-sfml-lib
Мобильная версия