SFML community forums

Help => General => Topic started by: AgonizingBroadcast on May 06, 2013, 12:23:34 am

Title: Linking Error
Post by: AgonizingBroadcast on May 06, 2013, 12:23:34 am
I'm getting a linking error(I think) when trying to compile my program.

This is my Game.h file:
#ifndef GAME_H
        #define GAME_H

#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>

class Game {
        private:
                sf::RenderWindow *window;
        public:
                Game();
                ~Game();
                void start();
};

#endif
 

And this is my Game.cpp file:
#include "Game.h"

Game::Game() {
        this->window = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "Pong", !sf::Style::Resize | sf::Style::Close);
}

Game::~Game() {

}

void Game::start() {

}
 

This is the build script I am using, the dll files are in the same directory as the code files.
g++ -o Pong.exe Main.cpp Game.h Game.cpp -lsfml-system -lsfml-graphics -lsfml-audio
 

Any way to fix this?
Title: Re: Linking Error
Post by: Nexus on May 06, 2013, 12:28:58 am
You need to link sfml-window, and consider the correct link order. Please read the tutorial...

By the way, what should the negation operator in !sf::Style::Resize mean? And why do you need manual memory management and a destructor? Just define your class as follows:
class Game
{
    private:
        sf::RenderWindow window; // No pointer
    public:
        Game();
        void start();
};
Game::Game()
: window(sf::VideoMode(800, 600, 32), "Pong", sf::Style::Resize | sf::Style::Close)
{
    // Because of the constructor initializer list, the body remains empty
}

void Game::start()
{
}
Title: Re: Linking Error
Post by: AgonizingBroadcast on May 06, 2013, 12:38:43 am
You need to link sfml-window, and consider the correct link order. Please read the tutorial...

By the way, what should the negation operator in !sf::Style::Resize mean? And why do you need manual memory management and a destructor? Just define your class as follows:
class Game
{
    private:
        sf::RenderWindow window; // No pointer
    public:
        Game();
        void start();
};
Game::Game()
: window(sf::VideoMode(800, 600, 32), "Pong", sf::Style::Resize | sf::Style::Close)
{
    // Because of the constructor initializer list, the body remains empty
}

void Game::start()
{
}

Thank you for the quick response :) All works fine now. I'm sorry for being a noob at this, I don't fully understand the concept of pointers and memory management(I come from a Java background)
Title: Re: Linking Error
Post by: Nexus on May 06, 2013, 12:43:09 am
You should read my answer here (http://en.sfml-dev.org/forums/index.php?topic=11388.msg79079#msg79079).
Title: Re: Linking Error
Post by: Laurent on May 06, 2013, 07:55:01 am
Next time you have an error, please write it in your post... How can we help if we don't know what's wrong? :P
Title: Re: Linking Error
Post by: AgonizingBroadcast on May 06, 2013, 02:00:22 pm
Next time you have an error, please write it in your post... How can we help if we don't know what's wrong? :P

Sorry! D: I completely forgot to post the error, my bad. Won't happen again I assure you.
Title: Re: Linking Error
Post by: Nexus on May 06, 2013, 03:19:31 pm
How can we help if we don't know what's wrong? :P
It's just a matter of having the right crystal ball :P