Why does the console even appear using a library to create a window?

Asked

Viewed 48 times

2

I wanted to understand why the console also opens when a program is made using the SDL2 library. I am using codeblocks in windows 10.

How do not appear the console and only appear the window generated through SDL2?

#include <iostream>
#include <SDL.h>

int main(int argc, char *argv[])
{
    SDL_Init(SDL_INIT_VIDEO);

    SDL_Window *window = SDL_CreateWindow(
                                          "Funcionou!",
                                          SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                          800, 600,
                                          SDL_WINDOW_SHOWN
    );

    SDL_Renderer *renderer = SDL_CreateRenderer(window,-1,0);

    SDL_SetRenderDrawColor(renderer, 255,0,0,255);

    SDL_RenderClear(renderer);

    SDL_RenderPresent( renderer );

    SDL_Delay(3000);

    return (0);
}
  • I never used SDL and so I may be mistaken, but it seems that this application was made for console and not for Windows. Among other things they should use the WinMain() https://docs.microsoft.com/en-us/windows/win32/learnwin32/winmain--the-application-entry-point. But she may already have that, but she would have to compile it in a certain way to do this..

  • In fact, in the SDL2 version for Windows, the WinMain() is initialized "under the hood", the main that appears is not the function main that would be expected in a C++ program- for example, if you remove the arguments int argc, char** argv you have a compilation error - but yes a define or something worth it from a function called SDL_main().

  • If you were using msvc just set Subsystem as windows

1 answer

2


If you want to remove the console in Codeblock, on the home screen select in the menu bar, the item project and then the item properties. Then the program will open the next screen:

inserir a descrição da imagem aqui

On this screen, you will go on the tab Build Targets and then in the field Type> you select the option Gui application.Check out:

inserir a descrição da imagem aqui

Once done, the console should disappear.

Finally, a brief comment: the console is very useful in the production phase to debug, so I only remove the console when the program is ready.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.