"winapifamily.h: No such file or directory" when compiling SDL in Code::Blocks

53,584

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__) */
Share:
53,584
user3427293
Author by

user3427293

Updated on February 19, 2020

Comments

  • user3427293
    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
    user3427293 about 10 years
    I do not have a 'Windows Kits' folder on my C:. Is that a Windows 8 thing? I'm running 64bit Win 7.
  • user3427293
    user3427293 about 10 years
    Just 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
    Xavi Montero almost 10 years
    Like 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 (without cmake, with direct makefile for mingw) also failed with the same error. I just placed this file into SDL2-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
    David Ludwig almost 10 years
    Yes, the changes were committed to the official, SDL2 repo.
  • David Ludwig
    David Ludwig almost 10 years
    To 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
    marknuzz almost 8 years
    Above link is broken
  • Zsar
    Zsar almost 8 years
    This 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
    David Ludwig over 7 years
    Zsar, 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
    Sahib Yar almost 7 years
    I am also having the same issue in when compiling with SDL2 2.0.4 with visual studio 2017
  • David Ludwig
    David Ludwig almost 7 years
    Sahib, 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