I have an application that runs fine on Ubuntu but immediately exit at startup, WITHOUT ANY ERRORS, on Windows.
It seems that main() function is not entered.
Application has been compiled without errors and it uses SDL_image.h. When (in the same application) the code that uses SDL Image was not present the application was running fine.
In the .exe directory there are all the needed dlls, SDL2.dll, libjpeg-9.dll, libpng16-16.dll, libtiff-5.dll, libwebp-7.dll, SDL2_image.dll and zlib1.dll.
IMG_Init() is called before any other image functions in this way:
(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG)
and, as I said before, tha application runs without problems on Ubuntu.
This is a reproducible example.
This code works:
makefile
CC = gcc -fno-pie -no-pie -m32
CFLAGS = -IC:/sdl2/include -O0 -ggdb
LIBS = -LC:/sdl2/lib/x86 -lSDL2main -lSDL2
all:
$(CC) $(CFLAGS) main.c $(LIBS) -o application.exe
main.c
#include <stdio.h>
#include "SDL.h"
int main(int argc, char **argv)
{
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
{
SDL_Log("SDL fails to initialize video subsystem!\n%s", SDL_GetError());
return -1;
}
else
printf("SDL Video was initialized fine!\n");
return 0;
}
This code, where I use SDL Image library, doesn't do nothing, no errors, immediately exits:
makefile
CC = gcc -fno-pie -no-pie -m32
CFLAGS = -IC:/sdl2/include -IC:/sdl2_image/include -O0 -ggdb
LIBS = -LC:/sdl2/lib/x86 -LC:/sdl2_image/lib/x86 -lSDL2main -lSDL2 -lSDL2_image
all:
$(CC) $(CFLAGS) main.c $(LIBS) -o application.exe
main.c
#include <stdio.h>
#include "SDL.h"
#include "SDL_image.h"
int main(int argc, char **argv)
{
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
{
SDL_Log("SDL fails to initialize video subsystem!\n%s", SDL_GetError());
return -1;
}
else
printf("SDL Video was initialized fine!\n");
if((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG)
{
SDL_Log("SDL fails to initialize image handler!\n%s", IMG_GetError());
return -1;
}
else
printf("SDL Image was initialized fine!\n");
return 0;
}
As I said before, it seems that the problem is the windows library (or the environment) and this is why I didn't add a reproducible code before