I am on Ubuntu, trying to compile a C/SDL2 program to Windows using MinGW. I have included the development libraries and includes of both SDL2 and SDL_image like this:
But I am running into an issue with the include files, I am getting this error:
In file included from ./src/files/game.c:3:
/home/gnxrly/Downloads/SDL2_image-2.6.0/i686-w64-mingw32/include/SDL2/SDL_image.h:32:10: fatal error: SDL.h: No such file or directory
32 | #include "SDL.h"
| ^~~~~~~
compilation terminated.
I’m only linking -lSDL2, -lSDL2_image and -lpng for Linux, so those are the Windows equivalents. Do I also need to find the devel files for SDL1 for SDL_image to work?
/*
Linux:
gcc main.c -o main -lSDL2
Windows:
Folgende Datei muss im Stamm-Ordner des Projektes sein libSDL2main.a
x86_64-w64-mingw32-gcc main.c -o main.exe -lmingw32 -lSDL2main -lSDL2 -mwindows -I/usr/local/include -L/usr/local/bin -L.
*/
#include <SDL2/SDL.h>
#include <SDL2/SDL_main.h>
int main(int argc, char *argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window = SDL_CreateWindow("An SDL2 window", 0, 0, 640, 480, SDL_WINDOW_OPENGL);
SDL_Delay(3000);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
I have the following demo, which can be cross-compiled under Linux. These two paths still need to be adjusted -I/usr/local/include -L/usr/local/bin
And you also need to have the following lib: libSDL2main.a
I don’t understand. I don’t think anything is wrong with my program because it compiles and works flawlessly on Linux with gcc. The error is coming from the SDL_main.h file in the devel include that I downloaded for the cross-compilation.
I tried adding #include <SDL2/SDL_main.h> to all my files, as well as adding -lSDL2main -lSDL2 -mwindows to the flags, but the issue persists.
Also, where do I find libSDL2main.a and how do I link it?
According to the error message, what’s missing here is adding the SDL2 include dir itself to the search path, like -I ~/Downloads/SDL2-2.30.3/i686-w64-mingw32/include/SDL2
If linker errors turn up afte fixing this, they may be due to missing libSDL2main, which is part of the download so -lSDL2main should generally work, but see also [SDL2.x] WinMain vs. main - #5 by Daniel_Gibson for the correct order of linking SDL2 and SDL2main with MinGW
According to the error message, what’s missing here is adding the SDL2 include dir itself to the search path, like -I ~/Downloads/SDL2-2.30.3/i686-w64-mingw32/include/SDL2
/usr/bin/i686-w64-mingw32-ld: /tmp/cc6JCKhW.o:init.c:(.text+0x5da): undefined reference to `IMG_Load'
I am getting this error for each time that I’m calling this function. I tried including the SDL2 directory inside the SDL2_image devel include folder like this