[英]SDL2_image not found
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:但是在运行以下 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.不完全确定我安装的 SDL_image。 I am running this on Ubuntu.我在 Ubuntu 上运行这个。
这个问题可以通过安装libsdl2-image-dev
包来解决:
apt install libsdl2-image-dev
Run apt-file search SDL_image.h
The result will tell you the location of the include file.运行apt-file search SDL_image.h
结果会告诉你包含文件的位置。
For instance, /usr/include/SDL2/SDL_image.h
was returned.例如,返回了/usr/include/SDL2/SDL_image.h
。 So, when you want to include SDL_image.h
, write everything after the include/
in between <
>
.因此,当您想要包含SDL_image.h
,请在<
>
之间的include/
之后写入所有内容。
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.有关此解决方案的原始讨论,请参阅问题的评论。
From SDL documentation, it says that add 'lSDL_image' to the end of the compile line.从 SDL 文档中,它说将“lSDL_image”添加到编译行的末尾。
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.这是参考-> https://www.libsdl.org/projects/docs/SDL_image/SDL_image.html 2.2 节编译。
So for SDL2, you just need to change 'lSDL_image' to 'lSDL2_image'.因此,对于 SDL2,您只需要将 'lSDL_image' 更改为 'lSDL2_image'。
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.对于Windows + SDL2-2.0.8 + SDL_image-2.0.4 + Codeblocks
您已将Runtime Binaries
和Development Libraries
到编译器和链接器。 Or else, you'll get the error SDL2_image not found
, even with having the dll
in your program's directory, this occurs.否则,您将收到错误SDL2_image not found
,即使您的程序目录中有dll
,也会发生这种情况。 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.示例:如果您的资源是分开的,您将SDL2
两个资源加上您的标准SDL2
路径添加到您的编译器和链接器中。 Warning: SDL2_image.h has it's headers assuming that the headers are in the same folder as the SDL2 framework.警告:假设标头与 SDL2 框架位于同一文件夹中,SDL2_image.h 具有标头。 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>
.如果您收到有关图像标题的错误,请在路径中包含来自 SDL 框架的子文件夹SDL2
,然后您应该在程序中包含SDL2
: include <SDL.h>
而不是include <SDL2/SDL.h>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.