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

Author Topic: Getting rid of the console on windows with mingw  (Read 10523 times)

0 Members and 1 Guest are viewing this topic.

blueeyedlion

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Getting rid of the console on windows with mingw
« on: April 16, 2012, 02:12:30 am »
I want to be able to get rid of the console window, but still be able to use the same code on linux.  I am using SFML 1.6 and g++ with mingw on windows.  All of the explanations I have found have either been for code::blocks or visual studio.  Any help would be greatly appreciated.

Erebus

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Getting rid of the console on windows with mingw
« Reply #1 on: April 16, 2012, 04:19:14 am »
Try putting this as the main function:

Code: [Select]
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Getting rid of the console on windows with mingw
« Reply #2 on: April 16, 2012, 07:50:10 am »
Or link to sfml-main, which does the same thing and allows your code to remain clean.
Laurent Gomila - SFML developer

cRichards

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Getting rid of the console on windows with mingw
« Reply #3 on: April 16, 2012, 11:27:41 pm »
The simplest way to do this is to right click your project and click "Properties..". Click the "Build targets" tab and find where it says "Type:". It probably set to "console application" in the drop down menu. Change it to "GUI application" and/or click the check box underneath it that says "Pause when execution ends".

Wow. I completely misread the problem. I guess I thought you were looking for a solution in Code::blocks. Sorry about that.
« Last Edit: April 16, 2012, 11:31:47 pm by cRichards »

Silvah

  • Guest
Re: Getting rid of the console on windows with mingw
« Reply #4 on: April 17, 2012, 05:20:31 pm »
Compile and link with -mwindows. The compiler, the linker, and the runtime library headers will take care of the rest.

You shouldn't need to link with sfml-main, an equivalent is linked in automatically if there's no WinMain function.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Getting rid of the console on windows with mingw
« Reply #5 on: April 17, 2012, 05:30:01 pm »
Quote
You shouldn't need to link with sfml-main, an equivalent is linked in automatically if there's no WinMain function.
Really? Is it handled directly by gcc?
Laurent Gomila - SFML developer

Silvah

  • Guest
Re: Getting rid of the console on windows with mingw
« Reply #6 on: April 17, 2012, 08:23:30 pm »
Quote
You shouldn't need to link with sfml-main, an equivalent is linked in automatically if there's no WinMain function.
Really? Is it handled directly by gcc?
Not by the GCC itself, rather by the runtime library. It just provides an appropriate object file, then the linker links it in when it's needed and ignores when it's not (like all other object files).

blueeyedlion

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Getting rid of the console on windows with mingw
« Reply #7 on: April 18, 2012, 06:21:54 am »
Linking with sfml-main didn't work, but -mwindows did.  Thank you!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Getting rid of the console on windows with mingw
« Reply #8 on: April 18, 2012, 08:06:23 am »
Quote
Linking with sfml-main didn't work, but -mwindows did.  Thank you!
Just to be clear, sfml-main allows you to keep a main() entry point instead of WinMain() after you add the -mwindows flag.
Well, at least with Visual C++.
Laurent Gomila - SFML developer

aNewHobby

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • Live 4 Ever Or Die Trying
Re: Getting rid of the console on windows with mingw
« Reply #9 on: May 09, 2012, 06:38:13 pm »
I am not sure what you mean in this thread but it seams to be able my problem. Basically I am using SFML2.

I am linking to

sfml-graphics.lb
sfml-window.lib
sflm-system.lib
sfml-main.lib

I am compiling on "release"... I get same error on debug if i add the -d .... what happens is that the sfml app runs, but it get a crash when i try to exit. I did a empty win32 app.

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(1280, 720), "TehTrix - Yet Another Tetris Clone", sf::Style::Titlebar | sf::Style::Close);
    sf::Text text("Hello SFML");

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(text);
        window.display();
    }
    return EXIT_SUCCESS;
}

This is my code.. it is just to try and get it running. The thing is I do not know what u guys mean but ...

add the -mwindows flag.

---- EDIT ----

I found this post..

Yep, the ATI fix is implemented but it still crashes when you use the default font.

So changed the code to this....

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(1280, 720), "TehTrix - Yet Another Tetris Clone", sf::Style::Titlebar | sf::Style::Close);

       

        // Load the text font
        sf::Font font;
        if (!font.loadFromFile("../../trunk/resource/font/sansation.ttf"))
                return EXIT_FAILURE;

        // Initialize the pause message
        sf::Text pauseMessage;
        pauseMessage.setFont(font);
        pauseMessage.setCharacterSize(40);
        pauseMessage.setPosition(170.f, 150.f);
        pauseMessage.setColor(sf::Color::White);
        pauseMessage.setString("Welcome to SFML");

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(pauseMessage);
        window.display();
    }
    return EXIT_SUCCESS;
}
 

and now it don't crash... but... um.. what exactly is sflm-main?
« Last Edit: May 09, 2012, 07:37:08 pm by aNewHobby »
Twitter: @Jyinkies
My Own Little Spot on the Net: - Live4everOrDieTrying.info (Blog)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Getting rid of the console on windows with mingw
« Reply #10 on: May 09, 2012, 07:44:20 pm »
Quote
what exactly is sflm-main?
Isn't it explained above, in my previous post? What don't you understand exactly?
Laurent Gomila - SFML developer

aNewHobby

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • Live 4 Ever Or Die Trying
Re: Getting rid of the console on windows with mingw
« Reply #11 on: May 10, 2012, 12:57:59 am »
Quote
what exactly is sflm-main?
Isn't it explained above, in my previous post? What don't you understand exactly?

Well for starters...

"add the -mwindows flag." - What dose this mean.. and how do I do it in VS2010?

Also, where in the documentation / tutorials is sfml-main even mentioned?
Twitter: @Jyinkies
My Own Little Spot on the Net: - Live4everOrDieTrying.info (Blog)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Getting rid of the console on windows with mingw
« Reply #12 on: May 10, 2012, 08:06:19 am »
Quote
"add the -mwindows flag." - What dose this mean.. and how do I do it in VS2010?
Forget about that, and just read the VS 2010 tutorial ;)

Quote
Also, where in the documentation / tutorials is sfml-main even mentioned?
Probably in the first tutorial of the sfml-window package ("Opening a window").
Laurent Gomila - SFML developer