【问题标题】:SDL/SDL_image.h: No such file or directorySDL/SDL_image.h:没有这样的文件或目录
【发布时间】:2011-10-14 04:30:25
【问题描述】:

我正在尝试关注Lazy Foo's 教程。但是当我尝试运行他的一个示例时,我得到了这个编译器错误:

错误:SDL/SDL_image.h:没有这样的文件或目录

编译器/链接器设置正确,我在 Windows XP 上使用 Code::Blocks。

但是,问题只是没有 SDL_image.h。我已经检查了它应该是的文件夹。我尝试再次下载 SDL 库并再次检查,仍然没有 SDL_image.h 文件。 SDL_image.h 文件去哪了?

我下载的库是来自此链接的 Win32 的“开发库”下的“SDL-devel-1.2.14-mingw32.tar.gz”:http://www.libsdl.org/download-1.2.php

【问题讨论】:

  • AFAIK 包含 SDL 相关标头的“官方”方式是通过 #include "SDL.h"
  • @trenki: 虽然它通常位于 unixlike boxery 上的/usr/include/SDL
  • @phresnel:我知道,这就是为什么sdl-config --cflags --libs 包含-I/usr/include/SDL

标签: c++ sdl codeblocks


【解决方案1】:

您需要单独安装SDL_image。它不随 SDL 提供。

【讨论】:

  • 对于使用 SDL2 的用户,文件名已更改为“SDL2_image.h”。请参阅文档:wiki.libsdl.org/MigrationGuide#line-435
  • 在我的机器上,该文件位于 /usr/local/include/SDL2/SDL_image.h。本质上,需要从“SDL2/SDL_image.h”导入并与 -lSDL_image 链接。
  • @BitFracture 这可能取决于,对我来说仍然是SDL_image.h,确切地说是SDL2/SDL_image.h
  • @Hi-Angel 这里重要的一点是,它可能不会对每个人都在同一个地方。希望知道这一点可以防止一些面部手掌。
  • 在 macOS 上,您可以通过 brew install sdl2 sdl2_image 获得此功能,至少在构建 Brogue CE 时是这样。
【解决方案2】:

您需要像其他答案中提到的那样安装 SDL_image 库,如果您使用的是基于 Debian 的系统,则只需使用以下命令进行安装:

sudo apt-get install libsdl-image1.2-dev

【讨论】:

    【解决方案3】:

    在lazyfoo的第三篇教程中已经完整讲解了。

    基本上,您必须在编译行中添加“-lSDL_image”。

    【讨论】:

      【解决方案4】:

      在您使用 Windows 的情况下,您应该先安装 sdl_image 然后

      #include <SDL_image.h>
      

      不是

      #include <SDL/SDL_image.h>
      

      如果您使用的是 linux 并且您的 sdl-image 包安装到 /usr/include/SDL 那么您需要使用

      #include <SDL_image.h>
      

      在大多数情况下,当您在 linux 中从源代码安装时。你的包裹可能不在/usr/include/SDL

      在这种情况下,我使用

      #include <SDL/SDL_image.h>
      

      它可以工作

      【讨论】:

        【解决方案5】:

        我有同样的问题“错误:SDL/SDL_image.h:没有这样的文件或目录”,我通过这样做解决了这个问题:http://wiki.codeblocks.org/index.php?title=Using_SDL_with_Code::Blocks ...查看名称为“项目的构建选项”的图片并写下东西在我的情况下,在那个红色圆圈内它有所帮助。祝你好运! (抱歉英语不好):P

        【讨论】:

          【解决方案6】:

          对于尝试此操作的任何人,更新将实际添加“-lSDL2_image”到您的编译行。其他人都只是拥有 -lSDL_image",它在 SDL2 发布时发生了变化。之后,只需转到 bin 并将所有 .dll 文件添加到 System32 中,您就应该准备好了!

          【讨论】:

            【解决方案7】:

            你必须下载 “SDL_image-devel-1.2.4-VC6.zip” 对于代码块 下载链接 ” http://www.libsdl.org/projects/SDL_image/release/SDL_image-devel-1.2.4-VC6.zip

            复制包含文件夹中的文件,提取后您将在 zip 文件中找到这些文件。在我的情况下,将其粘贴到 C:\SDL\include\SDL 或其他文件所在的目录 SDL *.h 存在。

            类似地,复制 zip 文件的 lib 文件夹中的文件并将其粘贴到 C:\SDL\lib 或其他 lib 文件所在的文件夹中。 然后将存档中存在的所有 *.dll 文件复制到 C:\windows\system32 此外,您必须通过打开设置 > 编译器和调试器 > 链接器将“-lSDL_image”添加到编译行。

            然后打开一个空文件项目并将空文件添加到项目然后#include "SDL\SDL_image.h" 希望对你有用!!

            或者

            首先从上面给出的链接下载 SDL_image-devel-1.2.4-VC6.zip 和 转到链接>>http://www.lazyfoo.net/SDL_tutorials/lesson03/windows/codeblocks/index.php以获得更详细的解释。

            【讨论】:

              【解决方案8】:

              适用于我的 (32b) 的 SDL2 Windows 安装程序(C 语言):

              1. 下载SDL2_image-devel-2.0.5-mingw.tar.gzSDL2_image-2.0.5-win32-x86.zip(32 选择其他 64)来自这里:https://www.libsdl.org/projects/SDL_image/

              2. 复制SDL2_image-devel-2.0.5-mingw\SDL2_image-2.0.5\i686-w64-mingw32\include\SDL2\SDL_image.h到您的所有标题都是我的情况的 SDL 文件夹 "MinGW\include\SDL2"

              3. 将内容从SDL2_image-devel-2.0.5-mingw\SDL2_image-2.0.5\i686-w64-mingw32\bin复制到\MinGW\bin".

              4. 复制以下内容:"SDL2_image-devel-2.0.5-mingw\SDL2_image-2.0.5\i686-w64-mingw32\lib" "MinGW\lib"

              5. 包含这样的标题:

                    #include <SDL2/SDL_image.h>
                
              6. 在你的 makefile 中链接它(参见这个'... -llibSDL2_image ...'):

                      build:
                          gcc -Wfatal-errors \
                          -std=c99 \
                          ./*.c \
                          -I"C:\libsdl\include" \
                          -L"C:\libsdl\lib" \
                          -lmingw32 \
                          -lSDL2main \
                          -lSDL2 \
                          -lSDL2 \
                          -llibSDL2_image \
                          -o example.exe
              
              1. 虚拟 CodeExample.c
                   #include <SDL2/SDL.h>
                   #include <SDL2/SDL_image.h>
                   #include <SDL2/SDL_timer.h>
                   #include <stdio.h>
                  
                  int main(int argc, char *args[])
                  {
                  
                      // attempt to initialize graphics and timer system
                      if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
                      {
                          printf("Error initializing SDL: %s\n", SDL_GetError());
                      }
                  
                      // Declare pointers
                      SDL_Window *window;
                      SDL_Renderer *renderer;
                      SDL_Texture *bitmapTex = NULL;
                      SDL_Surface *bitmapSurface = NULL;
                  
                      // Create an application window with the following settings:
                      window = SDL_CreateWindow(
                          "An SDL2 window",       // window title
                          SDL_WINDOWPOS_CENTERED, // initial x position
                          SDL_WINDOWPOS_CENTERED, // initial y position
                          840,                    // width, in pixels
                          480,                    // height, in pixels
                          SDL_WINDOW_OPENGL       // flags - see below
                      );
                  
                      // Check that the window was successfully created
                      if (!window)
                      {
                          // In the case that the window could not be made...
                          printf("Could not create window: %s\n", SDL_GetError());
                          SDL_Quit();
                          return 1;
                      }
                  
                      // create renderer which sets up graphics hardware
                      Uint32 render_flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC;
                      renderer = SDL_CreateRenderer(window, -1, render_flags);
                      if (!renderer)
                      {
                          printf("error creating renderer: %s\n", SDL_GetError());
                          SDL_DestroyWindow(window);
                          SDL_Quit();
                          return 1;
                      }
                  
                      // Load theimage into memory using SDL_Image library function
                      bitmapSurface = IMG_Load("image.png");
                      bitmapTex = SDL_CreateTextureFromSurface(renderer, bitmapSurface);
                  
                      SDL_FreeSurface(bitmapSurface);
                      if (!bitmapTex)
                      {
                          // In the case that the window could not be made...
                          printf("Error creating texture: %s\n", SDL_GetError());
                          SDL_DestroyRenderer(renderer);
                          SDL_DestroyWindow(window);
                          SDL_Quit();
                          return 1;
                      }
                  
                      // The window is open: could enter program loop here (see SDL_PollEvent())
                      while (1)
                      {
                          SDL_Event e;
                          if (SDL_PollEvent(&e))
                          {
                              if (e.type == SDL_QUIT)
                              {
                                  break;
                              }
                          }
                  
                          // Clear the window
                          SDL_RenderClear(renderer);
                          SDL_RenderCopy(renderer, bitmapTex, NULL, NULL);
                          SDL_RenderPresent(renderer);
                      }
                  
                      SDL_DestroyTexture(bitmapTex);
                      SDL_DestroyRenderer(renderer);
                      SDL_DestroyWindow(window);
                  
                      SDL_Quit();
                  
                      return 0;
                  }
              

              【讨论】:

              • SDL2_image-devel-2.0.5-VC.zip 用于 Visual Studio,将其与 MinGW 一起使用是个坏主意。我很惊讶它对你有用。你应该使用SDL2_image-devel-2.0.5-mingw.tar.gz
              • 是的,你是对的,是错误的文件夹,对不起,我的错误,评论已更改。
              猜你喜欢
              • 1970-01-01
              • 2012-11-04
              • 1970-01-01
              • 2021-06-24
              • 2023-02-22
              • 2015-02-20
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多