编译Code :: Blocks中的SDL时,"winapifamily.h:没有这样的文件或目录"

use*_*293 48 c++ sdl codeblocks sdl-2

我正在使用LazyFoo的SDL2.0教程,使用Code :: Blocks 13.12.我已经毫无困难地将SDL2链接并在VS2010中运行但是已经更改了IDE并遇到了这个错误:

winapifamily.h:没有这样的文件或目录

我认为一切都是正确的.我已将程序指向我的SDL2 include和lib目录.

Buildlog :(文件中出现错误:..\include\SDL2\SDL_platform.h)

=== Build:在SDL2_Setup中调试(编译器:GNU GCC编译器)===

致命错误:winapifamily.h:没有这样的文件或目录

===构建失败:1个错误,0个警告(0分钟,0秒(秒))===

这是我第一次在这里问一个问题.我在Google上找到答案并在此处搜索现有的问题/答案,但无法解决问题.这是我的代码.

我的代码:

// Using SDL and standard IO
#include <SDL.h>
#include <stdio.h>

// Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

int main( int argc, char* args[] )
{
    // The window we'll be rendering to
    SDL_Window* window = NULL;

    // The surface contained by the window
    SDL_Surface* screenSurface = NULL;

    // Initialize SDL
    if( SDL_Init( SDL_INIT_VIDEO) < 0 )
    {
        printf( "SDL could not initialize! SDL_GetError: %s\n", SDL_GetError() );
    }
    else
    {
        // Create window
        window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
        if( window == NULL )
        {
            printf( "Window could not be created! SDL_GetError: %s\n", SDL_GetError() );
        }
        else
        {
            // Get window surface
            screenSurface = SDL_GetWindowSurface( window );

            // Fill the surface white
            SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF));

            // Update the surface
            SDL_UpdateWindowSurface( window );

            // Wait two seconds
            SDL_Delay( 2000 );
        }
    }

    // Destroy window
    SDL_DestroyWindow( window );

    // Quit SDL subsystems
    SDL_Quit();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Dav*_*wig 63

更新:SDL 2.0.4现已推出,包括针对此错误的修复程序,可从http://libsdl.org/download-2.0.php下载


这是SDL 2.0.3中的一个错误.已经为SDL的下一个版本提交了修复程序.在此期间,这里是SDL_platform.h的固定副本的链接:

https://hg.libsdl.org/SDL/raw-file/e217ed463f25/include/SDL_platform.h

如果您将文件放入SDL 2.0.3的include\SDL2 \目录中,覆盖原始文件,您的应用程序应编译正常.

  • 添加:该更改是在2.0.3之后提交的.下一个版本应该包含修复程序.在发布之前,如果Dropbox链接死亡,这里是另一个指向固定副本的链接:https://hg.libsdl.org/SDL/raw-file/e217ed463f25/include/SDL_platform.h (3认同)
  • 当与Visual Studio 2015 U3一起使用WinXP兼容性工具集`vs140_xp`时,此问题在SDL2 2.0.4中返回.似乎从U3开始,不再自动设置宏`_USING_V110_SDK71_`.我不清楚这是SDL2的问题还是VS2015U3的问题. (2认同)

Nei*_*gan 10

快速修复.在SDL_platform.h中注释掉第121到132行.当发生错误时,文件会加载到C :: B中.保存并建立起来!


小智 1

我有这个问题。去

C:\Program Files (x86)\Windows Kits\8.0\Include\shared
Run Code Online (Sandbox Code Playgroud)

并找到winapifamily.h,然后将其复制到您的

..\Mingw\Include\ folder
Run Code Online (Sandbox Code Playgroud)

编辑:我想我有 Windows 工具包文件,因为 Visual Studio 2012 或更高版本,抱歉。我很高兴你能解决你的问题。

是的,问题出在该标头中(SDL_plataform.h 版本 SDL 2.0.3 中的第 117 行到 134 行):

#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
/* Try to find out if we're compiling for WinRT or non-WinRT */
/* If _USING_V110_SDK71_ is defined it means we are using the v110_xp or v120_xp toolset. */
#if defined(__MINGW32__) || (defined(_MSC_VER) && (_MSC_VER >= 1700) && !_USING_V110_SDK71_)    /* _MSC_VER==1700 for MSVC 2012 */
#include <winapifamily.h>
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
#undef __WINDOWS__
#define __WINDOWS__   1
/* See if we're compiling for WinRT: */
#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
#undef __WINRT__
#define __WINRT__ 1
#endif
#else
#undef __WINDOWS__
#define __WINDOWS__   1
#endif /* _MSC_VER < 1700 */
#endif /* defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) */
Run Code Online (Sandbox Code Playgroud)