SDL2_image not found

做~自己de王妃 提交于 2021-01-22 07:41:02

问题


I am trying to compile the following code which has the headers:

#include <SDL2/SDL.h>
#include <SDL2_image/SDL_image.h>

However after running the following makefile:

g++ -std=c++11 src/main.cpp -lSDL2 -lSDL2_image

I get the following error:

fatal error: SDL2_image/SDL_image.h: No such file or directory
#include <SDL2_image/SDL_image.h>

Any suggestions? Not entirely sure about my installation of SDL_image. I am running this on Ubuntu.


回答1:


This problem can be solved through installing libsdl2-image-dev package:

apt install libsdl2-image-dev



回答2:


Run apt-file search SDL_image.h The result will tell you the location of the include file.

For instance, /usr/include/SDL2/SDL_image.h was returned. So, when you want to include SDL_image.h, write everything after the include/ in between < >.

Thus, includes should look like the following:

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>

See the question's comments for the original discussion regarding this solution.




回答3:


From SDL documentation, it says that add 'lSDL_image' to the end of the compile line.

    cc -o myprogram mysource.o `sdl-config --libs` -lSDL_image

or

    gcc -o myprogram mysource.c `sdl-config --libs` -lSDL_image

Here is the reference -> https://www.libsdl.org/projects/docs/SDL_image/SDL_image.html Section 2.2 Compiling.

So for SDL2, you just need to change 'lSDL_image' to 'lSDL2_image'.




回答4:


For Windows + SDL2-2.0.8 + SDL_image-2.0.4 + Codeblocks you've got the add both Runtime Binaries and Development Libraries to the compiler and linker. Or else, you'll get the error SDL2_image not found, even with having the dll in your program's directory, this occurs. Hopefully others find this helpful; I had to figure it out myself. Example: If your resources are separate, you'll be adding the two plus your standard SDL2 paths to your compiler and linker. Warning: SDL2_image.h has it's headers assuming that the headers are in the same folder as the SDL2 framework. If you get errors about the image header, include the sub-folder SDL2 from SDL framework in the path and then you should be including SDL2 in the program as: include <SDL.h> rather than include <SDL2/SDL.h>.



来源:https://stackoverflow.com/questions/33356965/sdl2-image-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!