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

Author Topic: Simple question regarding g++ and SFML_STATIC in header file vs main.cpp  (Read 5617 times)

0 Members and 3 Guests are viewing this topic.

Lamonte

  • Newbie
  • *
  • Posts: 46
    • View Profile
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");
}
« Last Edit: July 21, 2013, 05:51:09 pm by Lamonte »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
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. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Lamonte

  • Newbie
  • *
  • Posts: 46
    • View Profile
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++
« Last Edit: July 21, 2013, 06:01:51 pm by Lamonte »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
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++
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Lamonte

  • Newbie
  • *
  • Posts: 46
    • View Profile
Edit: I'm an idiot, I didn't have an underscore.  Man it's too early for this lol
« Last Edit: July 21, 2013, 06:27:16 pm by Lamonte »

 

anything