Closed
Description
I'm new to SDL, so apologize for any inconvenience in case my question is stupid.
I experienced this on Windows 10 with mingw gcc version 15.1.0 (x86_64-posix-seh-rev0, Built by MinGW-Builds project)
.
I need to check if my program takes arguments -h
or -v
etc and in that case, I don't want a window but certain text in the console.
I compiled the program using
gcc example.c -o main.exe ^
-ISDL3-3.2.16/x86_64-w64-mingw32/include ^
-LSDL3-3.2.16/x86_64-w64-mingw32/lib ^
-lSDL3 -mwindows
When I run the following program the following happens on the console:
E:\path\to\project>main --help
E:\path\to\project>Usage: main
This example does not take any command line arguments.
Why is this printed text after E:\path\to\project>
appears?
This does not happen if compiled without -mwindows
, but I don't want the console to appear if directly run from double-clicking it.
Minimal example:
#define SDL_MAIN_USE_CALLBACKS 1
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
static SDL_Window *window = NULL;
static SDL_Renderer *renderer = NULL;
#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
if (argc > 1) {
SDL_Log("Usage: %s\n", argv[0]);
SDL_Log("This example does not take any command line arguments.\n");
return SDL_APP_FAILURE;
}
SDL_SetAppMetadata("Example", "1.0", "com.example");
if (!SDL_Init(SDL_INIT_VIDEO)) {
SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
return SDL_APP_FAILURE;
}
if (!SDL_CreateWindowAndRenderer("example", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) {
SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
return SDL_APP_FAILURE;
}
return SDL_APP_CONTINUE;
}
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS;
}
return SDL_APP_CONTINUE;
}
SDL_AppResult SDL_AppIterate(void *appstate) {
return SDL_APP_CONTINUE;
}
void SDL_AppQuit(void *appstate, SDL_AppResult result) {
}
Thanks!
Metadata
Metadata
Assignees
Labels
No labels