0

I'm trying to build a windows executable for a C++ application I've made that uses SDL2, and SDL_Image. I've seemingly managed to include the SDL libraries and headers just fine, but now I'm trying to include the SDL_Image ones. The command I'm currently using is as follows:

i686-w64-mingw32-gcc -lSDL2main -lSDL2 -I ~/SDL/SDL2-devel-2.0.22-mingw/SDL2-2.0.22/i686-w64-mingw32/include -L ~/SDL/SDL2-devel-2.0.22-mingw/SDL2-2.0.22/i686-w64-mingw32/lib  -o main32.exe main.cpp

But this gives me the error

main.cpp:4:10: fatal error: SDL2/SDL_image.h: No such file or directory
    4 | #include <SDL2/SDL_image.h>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.

I am aware that SDL_Image is a separate plugin, and I have already installed it.

What directory(s) do I need to specify to include SDL_Image in the build?

I'm on Ubuntu 22.

Edit: I have found the correct directories, and I now have the following command:

i686-w64-mingw32-gcc -lmingw32 -lSDL2main -lSDL2 -lSDL2_image \
-I /home/nick/SDL/SDL2-devel-2.0.22-mingw/SDL2-2.0.22/i686-w64-mingw32/include \
-L /home/nick/SDL/SDL2-devel-2.0.22-mingw/SDL2-2.0.22/i686-w64-mingw32/lib \
-I /home/nick/SDL/SDL2_image-devel-2.6.0-mingw/SDL2_image-2.6.0/i686-w64-mingw32/inclulde \
-L /home/nick/SDL/SDL2_image-devel-2.6.0-mingw/SDL2_image-2.6.0/i686-w64-mingw32/lib   \
-o main32.exe main.cpp

However, the command still gives me the same error. I have checked, and I am sure that the header file it cannot find is is the correct place.

Nick
  • 85
  • 8

1 Answers1

3

SDL2_Image is a plugin for SDL2, and needs to be downloaded separately. You also need to specify -I and -L for it, the same way you did for the SDL2 itself.

Also you forgot -lmingw32 (must be -lmingw32 -lSDL2main -lSDL2 in this exact order), plus -lSDL2_image after those.


As always, a shameless plug: I've made quasi-msys2, a cross-compilation environment that mimics (and is based on) MSYS2, but works on Linux.

Here's how you'd use it:

# Download Clang, LLD. Then:
git clone https://github.com/HolyBlackCat/quasi-msys2
cd quasi-msys2
make install _gcc _SDL2 _SDL2_image
env/shell.sh

Then:

$CXX main.cpp -o main `pkg-config --cflags --libs sdl2 SDL2_image`
HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
  • I already have SDL_Image installed and everything, I'm just not sure what directories to include. For SDL it was simple, as it's just the lib and include directories, however I can't seem to find anything similar in SDL_Image. I'll edit my question to clairify this. – Nick Jul 15 '22 at 19:48
  • Nevermind, I just found those dirs in the releases link you just sent. Thanks! – Nick Jul 15 '22 at 19:55
  • @Nick You're welcome! You can press the checkmark next to an answer to mark your question as solved. – HolyBlackCat Jul 17 '22 at 15:16
  • Unfortunately, it did not solve my issue. I have edited the qustion the reflect this. – Nick Jul 17 '22 at 22:35
  • @Nick You have a typo in your path, `inclulde` -> `include`. – HolyBlackCat Jul 18 '22 at 04:45
  • Indeed it does... Thanks, don't know how I missed that. They seemt to be included now, but I'm having some other issues. May be unrelated, so I will probably just make a new question. Thanks a bunch for the help. – Nick Jul 18 '22 at 16:46
  • @Nick Feel free to `@ping` me here when you do, maybe I can help. – HolyBlackCat Jul 18 '22 at 17:34