"winapifamily.h: No such file or directory" when compiling SDL in Code::Blocks
Solution 1
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
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:
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.
Solution 2
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!
Solution 3
I had that problem. Go to
C:\Program Files (x86)\Windows Kits\8.0\Include\shared
and find winapifamily.h
, then copy it to your
..\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.
Yeap, the problem is in that header (lines 117 to 134 in SDL_plataform.h version SDL 2.0.3):
#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__) */
user3427293
Updated on February 19, 2020Comments
-
user3427293 over 4 years
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:
winapifamily.h: No such file or directory
I think everything is linked correctly. I have pointed the program to my SDL2 include and lib directories.
Buildlog: (error is occuring in file: ..\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)) ===
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; }
-
user3427293 about 10 yearsI do not have a 'Windows Kits' folder on my C:. Is that a Windows 8 thing? I'm running 64bit Win 7.
-
user3427293 about 10 yearsJust after I posted this questions (2 hours ago at time of writing), it was answered elsewhere as revealed by further Google searching. This replacement for SDL_platform.h solved the issue for me: marshut.com/irzuki/sdl-platform-h.html
-
Xavi Montero almost 10 yearsLike a charm! - Compiling in an ubuntu (host) for windows 64 bit (target) with
mingw
, following this tuto willusher.io/sdl2%20tutorials/2013/08/15/lesson-0-mingw (withoutcmake
, with directmakefile
formingw
) also failed with the same error. I just placed this file intoSDL2-2.0.3/x86_64-w64-mingw32/include/SDL2
(which is the headers I include) and it solved the problem. The only diff with that version is a condition in an if that changed it's line. Thnx David. Just in case this dropbox disappears... is this file committed to the main repo?? -
David Ludwig almost 10 yearsYes, the changes were committed to the official, SDL2 repo.
-
David Ludwig almost 10 yearsTo add: that change was committed after 2.0.3. The next release should contain the fix. Until that release is made, if the Dropbox link dies, here's another link to the fixed copy: hg.libsdl.org/SDL/raw-file/e217ed463f25/include/SDL_platform.h
-
marknuzz almost 8 yearsAbove link is broken
-
Zsar almost 8 yearsThis issue returns in SDL2 2.0.4 when used with Visual Studio 2015 U3 using the WinXP compatibility toolset
vs140_xp
. Seems that as of U3 the macro_USING_V110_SDK71_
is no longer automatically set. It is not clear to me whether this is an issue with SDL2 or an issue with VS2015U3. -
David Ludwig over 7 yearsZsar, I am unable to reproduce your error, using either SDL 2.0.4, or the latest SDL2 code from hg.libsdl.org/SDL . Any chance that you could send me more information on how you are reproducing this? If there's a bug in SDL, I'd like to get a fix in, if possible.
-
Sahib Yar almost 7 yearsI am also having the same issue in when compiling with SDL2 2.0.4 with visual studio 2017
-
David Ludwig almost 7 yearsSahib, I would recommend grabbing the latest version of SDL, which is currently at 2.0.5, at the time of this writing. Downloads available at libsdl.org/download-2.0.php