Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Linking Error  (Read 2185 times)

0 Members and 1 Guest are viewing this topic.

AgonizingBroadcast

  • Newbie
  • *
  • Posts: 6
    • View Profile
Linking Error
« 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?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Linking Error
« Reply #1 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()
{
}
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

AgonizingBroadcast

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Linking Error
« Reply #2 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)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Linking Error
« Reply #3 on: May 06, 2013, 12:43:09 am »
You should read my answer here.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Linking Error
« Reply #4 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
Laurent Gomila - SFML developer

AgonizingBroadcast

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Linking Error
« Reply #5 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Linking Error
« Reply #6 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
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: