C++ 在 Code::Blocks 中编译 SDL 时出现“winapifamily.h: No such file or directory”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22446008/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"winapifamily.h: No such file or directory" when compiling SDL in Code::Blocks
提问by user3427293
I am following along with the SDL2.0 tutorials by LazyFoo, using Code::Blocks 13.12. I have had no trouble getting SDL2 linked and running in VS2010 but have changed IDE and come across this error:
我正在关注 LazyFoo 的 SDL2.0 教程,使用 Code::Blocks 13.12。我在 VS2010 中链接和运行 SDL2 没有遇到任何问题,但更改了 IDE 并遇到此错误:
winapifamily.h: No such file or directory
winapifamily.h:没有那个文件或目录
I think everything is linked correctly. I have pointed the program to my SDL2 include and lib directories.
我认为一切都正确链接。我已将程序指向我的 SDL2 包含和 lib 目录。
Buildlog:(error is occuring in file: ..\include\SDL2\SDL_platform.h)
构建日志:(文件中发生错误:..\include\SDL2\SDL_platform.h)
=== Build: Debug in SDL2_Setup (compiler: GNU GCC Compiler) ===
fatal error: winapifamily.h: No such file or directory
=== Build fails: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===
=== 构建:在 SDL2_Setup 中调试(编译器:GNU GCC 编译器)===
致命错误:winapifamily.h:没有那个文件或目录
=== 构建失败:1 个错误,0 个警告(0 分钟,0 秒)===
This is my first time asking a question on here. I did Google for an answer and search the existing questions/answers on here but was unable to solve the issue. Here is my code also.
这是我第一次在这里提问。我在谷歌上搜索了答案并在这里搜索了现有的问题/答案,但无法解决问题。这也是我的代码。
My Code:
我的代码:
// 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;
}
回答by David Ludwig
UPDATE: SDL 2.0.4 is now out, includes a fix for this bug, and is available for download at http://libsdl.org/download-2.0.php
更新:SDL 2.0.4 现已发布,包含针对此错误的修复程序,可从http://libsdl.org/download-2.0.php下载
This is a bug in SDL 2.0.3. A fix has been committed for SDL's next release. In the meantime, here's a link to the fixed copy of SDL_platform.h:
这是 SDL 2.0.3 中的一个错误。已为 SDL 的下一个版本提交了修复程序。同时,这里有一个指向 SDL_platform.h 的固定副本的链接:
https://hg.libsdl.org/SDL/raw-file/e217ed463f25/include/SDL_platform.h
https://hg.libsdl.org/SDL/raw-file/e217ed463f25/include/SDL_platform.h
If you drop the file into SDL 2.0.3's include\SDL2\ directory, overwriting the original, your app(s) should compile ok.
如果您将文件放入 SDL 2.0.3 的 include\SDL2\ 目录,覆盖原始文件,您的应用程序应该可以正常编译。
回答by Neil Regan
The quick fix. Comment out lines 121 to 132 inclusively in SDL_platform.h The file loads into C::B when the error occurs. Save it and build away!
快速修复。注释掉 SDL_platform.h 中的第 121 到 132 行,当错误发生时,文件会加载到 C::B 中。保存并建造!
回答by Gino Scarpino
I had that problem. Go to
我有那个问题。去
C:\Program Files (x86)\Windows Kits.0\Include\shared
and find winapifamily.h
, then copy it to your
并找到winapifamily.h
,然后将其复制到您的
..\Mingw\Include\ folder
Edit:I think I have windows kits files because of visual studio 2012 or later, sorry. I am glad you could solve your problem.
编辑:由于 Visual Studio 2012 或更高版本,我想我有 Windows 工具包文件,抱歉。我很高兴你能解决你的问题。
Yeap, the problem is in that header (lines 117 to 134 in SDL_plataform.h version SDL 2.0.3):
是的,问题出在该标题中(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__) */