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

Author Topic: I can't get my program working  (Read 2604 times)

0 Members and 1 Guest are viewing this topic.

DirtyBlasion

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
I can't get my program working
« on: January 16, 2017, 09:43:37 pm »
So I tryed to make a global class of renderwindow and manage it from a function. I want to make functions separate, later I will do a multy window system, that can be helpful.(I use c++, sfml and glew)

So firstly I initialized it global.
Code: [Select]
sf::RenderWindow *window;
Code: [Select]
     void Init()
    {

        int Width = 640, Height = 480;
        sf::ContextSettings settings;
        settings.depthBits = 24;
        settings.stencilBits = 8;
        settings.majorVersion = 3;
        settings.minorVersion = 3;
        settings.attributeFlags = sf::ContextSettings::Core;
        window = new sf::RenderWindow(sf::VideoMode(Width, Height), "DirtyCraft", sf::Style::Titlebar | sf::Style::Close, settings);
        window->setVerticalSyncEnabled(true);
        //window.setFramerateLimit(60);

        if(GLEW_OK != glewInit())
        {
            std::cout << "Failed to run Glew";
            window->close();
        }
    }
and I try to manage it from this. my main problem is:
Code: [Select]
window = new sf::RenderWindow(sf::VideoMode(Width, Height), "DirtyCraft", sf::Style::Titlebar | sf::Style::Close, settings);I want a fast reply, because I need to start my project faster, because I need to finish it in like 3 months.

jamesL

  • Full Member
  • ***
  • Posts: 124
    • View Profile
Re: I can't get my program working
« Reply #1 on: January 17, 2017, 03:52:30 am »
what's the problem ?

do you get an error at run time or compile time 

does the program run at all

does it compile at all

are you on windows, linux or mac

what version of sfml ?
which compiler ?

DirtyBlasion

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: I can't get my program working
« Reply #2 on: January 17, 2017, 08:27:55 am »
I get some weird compiler errors. I use MinGW as compiler. And all the block me is, how I give it the value of a constructor. And I thinked to create a temp class with new... but it didn't. And I dont know how I can make that = work without any compiler errors

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I can't get my program working
« Reply #3 on: January 17, 2017, 08:48:21 am »
Please read this carefully, and in your next post give us relevant details, like... the compiler errors ;)
Laurent Gomila - SFML developer

DirtyBlasion

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: I can't get my program working
« Reply #4 on: January 17, 2017, 09:24:18 am »
Code: [Select]
window = new sf::RenderWindow(sf::VideoMode(Width, Height), "DirtyCraft", sf::Style::Titlebar | sf::Style::Close, settings); so this line is with problems for me!

Code: [Select]
||=== Build: Debug in DirtyCraft (compiler: GNU GCC Compiler) ===|
obj\Debug\Display.o||In function `ZN7Display4InitEv':|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp|24|undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp|24|undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp|24|undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp|25|undefined reference to `_imp___ZN2sf6Window22setVerticalSyncEnabledEb'|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp|31|undefined reference to `_imp___ZN2sf6Window5closeEv'|
obj\Debug\Display.o||In function `ZN7Display3RunEv':|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp|77|undefined reference to `_imp___ZN2sf6Window5closeEv'|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp|73|undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp|84|undefined reference to `_imp___ZN2sf6Window7displayEv'|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp|70|undefined reference to `_imp___ZNK2sf6Window6isOpenEv'|
||error: ld returned 1 exit status|
||=== Build failed: 10 error(s), 0 warning(s) (0 minute(s), 3 second(s)) ===|
these are the errors! So 24 is
Code: [Select]
window = new sf::RenderWindow(sf::VideoMode(Width, Height), "DirtyCraft", sf::Style::Titlebar | sf::Style::Close, settings);  and the rest are functions of the class, reffered by ->.

but if I put * to RenderWindow
Code: [Select]
        window = new sf::RenderWindow*(sf::VideoMode(Width, Height), "DirtyCraft", sf::Style::Titlebar | sf::Style::Close, settings);
I get less errors

Code: [Select]
||=== Build: Debug in DirtyCraft (compiler: GNU GCC Compiler) ===|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp||In function 'void Display::Init()':|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp|24|error: new initializer expression list treated as compound expression [-fpermissive]|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp|24|warning: right operand of comma operator has no effect [-Wunused-value]|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp|24|warning: right operand of comma operator has no effect [-Wunused-value]|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp|24|error: cannot convert 'sf::ContextSettings' to 'sf::RenderWindow*' in initialization|
||=== Build failed: 2 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|
the interesting fact is that all the errors are now on 24 who is window = new...

If this is not enought to solve the problem, tell me, what is missing and I will give it

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I can't get my program working
« Reply #5 on: January 17, 2017, 09:27:31 am »
"undefined reference" errors mean that your code compiled fine, but that the linker failed to find some functions referenced in your code. These functions are SFML functions, which means that you didn't link SFML libraries correctly (ie. as explained in the tutorial) in your project settings.

If you write crap instead of correct code, yes you get other errors, from the compiler this time, but that's actually worse than before, even if the output is smaller ;)
Laurent Gomila - SFML developer

DirtyBlasion

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: I can't get my program working
« Reply #6 on: January 17, 2017, 09:44:55 am »
The problem is they are linked... because it worked befor cut it in more functions, and make it pointer... it worked perfect

so i did like this
Code: [Select]
window = &(sf::RenderWindow(sf::VideoMode(Width, Height), "DirtyCraft", sf::Style::Titlebar | sf::Style::Close, settings));and the errors have simplified a lot!
Code: [Select]
||=== Build: Debug in DirtyCraft (compiler: GNU GCC Compiler) ===|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp||In function 'void Display::Init()':|
C:\Users\George\Desktop\C++\DirtyCraft\Display.cpp|24|error: taking address of temporary [-fpermissive]|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Solved.... code blocks.... I dont understand why it forget the links... Thank you! Have a nice day
but, still how I can solve this??
« Last Edit: January 17, 2017, 10:19:53 am by DirtyBlasion »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I can't get my program working
« Reply #7 on: January 17, 2017, 10:16:02 am »
Quote
the errors have simplified a lot!
No... You write random stuff so the compiler no longer understands your code, and breaks after a single fatal error. Again, it doesn't mean that things are better. Stop writing random stuff and try to understand what's going on.

Quote
The problem is they are linked...
Not correctly, according to the linker errors.
Laurent Gomila - SFML developer

DirtyBlasion

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: I can't get my program working
« Reply #8 on: January 17, 2017, 10:20:59 am »
Solved. I was so confused... I knowed I linked them... but I don't understand why codeblocks forget the links. Thank you all, have a nice day/night!