Неопределенная ссылка на библиотеку C++ SFML "Game::*" [дубликат]C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Неопределенная ссылка на библиотеку C++ SFML "Game::*" [дубликат]

Сообщение Anonymous »

Я пытался заставить библиотеку SFML работать в VS Code, используя это руководство. Когда я пытаюсь скомпилировать с помощью Wingw64, он дает неопределенные ссылки на мой класс. У меня 64-битная версия Windows.
ОШИБКИ:

Код: Выделить всё

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
main.cpp

Код: Выделить всё

#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;
}
Game.hpp

Код: Выделить всё

#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();
};
game.cpp

Код: Выделить всё

#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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»