Visual Studio 2017无法打开" SDL.h"即使我将include目录添加到项目中

时间:2017-09-04 10:40:48

标签: c visual-studio compilation sdl-2

我尝试过类似问题的答案,而且还没有解决这个问题。我下载了全新的Visual Studio 2017和SDL2开发库。然后加载一些示例代码,使用SDL打开一个窗口进行测试,然后添加包含所有SDL头文件的include目录,并添加" SDL2.lib和SDL2main.lib"。但是,每当我尝试构建代码时,它都会向我吐出几个错误。我还包括一些屏幕截图。任何帮助将非常感激。 This shows where the include directory is located and that it's is added to additional include. This shows all the errors after building.

示例窗口代码

#include <SDL.h>
#include <stdio.h>

int main(int argc, char* argv[]) {

    SDL_Window *window;                    // Declare a pointer

    SDL_Init(SDL_INIT_VIDEO);              // Initialize SDL2

                                           // Create an application window with the following settings:
    window = SDL_CreateWindow(
        "An SDL2 window",                  // window title
        SDL_WINDOWPOS_UNDEFINED,           // initial x position
        SDL_WINDOWPOS_UNDEFINED,           // initial y position
        640,                               // width, in pixels
        480,                               // height, in pixels
        SDL_WINDOW_OPENGL                  // flags - see below
    );

    // Check that the window was successfully created
    if (window == NULL) {
        // In the case that the window could not be made...
        printf("Could not create window: %s\n", SDL_GetError());
        return 1;
    }

    // The window is open: could enter program loop here (see SDL_PollEvent())

    SDL_Delay(3000);  // Pause execution for 3000 milliseconds, for example

                      // Close and destroy the window
    SDL_DestroyWindow(window);

    // Clean up
    SDL_Quit();
    return 0;
}

错误

  • E1696无法打开源文件&#34; SDL.h&#34;
  • E0020标识符&#34; SDL_Window&#34;未定义
  • E0020标识符&#34; Window&#34;未定义
  • E0020标识符&#34; SDL_INIT_VIDEO&#34;未定义
  • E0020标识符&#34; SDL_WINDOWPOS_UNDEFINED&#34;未定义
  • E0020标识符&#34; SDL_WINDOW_OPENGL&#34;未定义
  • C1083无法打开包含文件:&#39; SDL.h&#39;:没有此类文件或目录

1 个答案:

答案 0 :(得分:1)

首先,我一直在构建调试,这给我带来了问题,解决方案是构建版本。然后使用lnk1561我必须告诉链接器哪个.lib文件与编译对象一起使用,然后添加这个“SDL2.lib; SDL2main.lib;“没有引号输入其他依赖项,然后最后添加到系统子系统”Windows(/ SUBSYSTEM:WINDOWS)“。在此页面上可以看到更好的解释... http://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/msvsnet2010u/index.php 谢谢大家的帮助!