SFML community forums

Help => General => Topic started by: Lamonte on July 21, 2013, 05:49:26 pm

Title: Simple question regarding g++ and SFML_STATIC in header file vs main.cpp
Post by: Lamonte on July 21, 2013, 05:49:26 pm
Before I had #define SFML_STATIC in the main.cpp file before compiling (and figuring out that you had to add each cpp file to the command else things wouldn't link properly, which is irrelevant) and I would get an error where RenderWindow wouldn't work.  Yet, I defined the SFML_STATIC definition before including my header file right.  So when I remove it from the main cpp file to the header file everything magically works again?  Why is this?

Is it because the SFML/Graphic.hpp etc.. files need to know about this constant before proceeding directly in the file itself before the header include?

(ps: disregard the include file names and what not they are irrelevant to teh question)

main.cpp
/**
 * Game Instance
 * @Author:     Lamonte & Jordan
 * @Copyright: 2013-
 */


#include "t_game.h"

int main() {
        G_Instance game;
        return 0;
}
 
g_instance.h
#ifndef GAME_CORE_H
#define GAME_CORE_H
#define SFML_STATIC
#include <SFML/Graphics.hpp>

class G_Instance {
        sf::RenderWindow window;
public:
        G_Instance();
};
#endif

g_instance.cpp
#include "t_game.h"

G_Instance::G_Instance() {
       
        window.create(sf::VideoMode(200,200), "Works");
}
Title: Re: Simple question regarding g++ and SFML_STATIC in header file vs main.cpp
Post by: eXpl0it3r on July 21, 2013, 05:55:08 pm
SFML_STATIC is not meant to be #defined in a header file, instead it's meant to be added as global switch in the project settings or the compile command.

I'm not sure what IDE or compiler you're using, but you can usually set such things in a property sheet of your project. :)
Title: Re: Simple question regarding g++ and SFML_STATIC in header file vs main.cpp
Post by: Lamonte on July 21, 2013, 05:57:50 pm
I'm using MinGW(g++) command line on windows.

ex.:
Quote
g++ file.cpp file2.cpp -o file.exe -Ic:\... -Lc:\... -lsfml-main -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -mwindow -static-libgcc -static-libstdc++
Title: Re: Simple question regarding g++ and SFML_STATIC in header file vs main.cpp
Post by: eXpl0it3r on July 21, 2013, 06:12:21 pm
You would end up with:
Quote
g++ file.cpp file2.cpp -o file.exe -Ic:\... -Lc:\... -DSFML_STATIC -lsfml-main -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -mwindow -static-libgcc -static-libstdc++
Title: Re: Simple question regarding g++ and SFML_STATIC in header file vs main.cpp
Post by: Lamonte on July 21, 2013, 06:16:35 pm
Edit: I'm an idiot, I didn't have an underscore.  Man it's too early for this lol