49

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;
}
1
  • I don't think VS 10 have this header file. it is a new header. check if your project have or missing some macro regarding the OS type.
    – SHR
    Mar 17, 2014 at 2:56

3 Answers 3

64

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.

7
  • 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?? Aug 20, 2014 at 9:24
  • Yes, the changes were committed to the official, SDL2 repo. Aug 27, 2014 at 19:06
  • 3
    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 Aug 27, 2014 at 19:17
  • 2
    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.
    – Zsar
    Jul 7, 2016 at 15:32
  • 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. Oct 5, 2016 at 20:36
11

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!

0
1

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__) */
3
  • I do not have a 'Windows Kits' folder on my C:. Is that a Windows 8 thing? I'm running 64bit Win 7. Mar 17, 2014 at 4:35
  • 1
    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 Mar 17, 2014 at 4:48
  • 1
    Above link is broken
    – marknuzz
    Jul 3, 2016 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.