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;
}
Martin G
  • 17,357
  • 9
  • 82
  • 98
user3427293
  • 491
  • 1
  • 4
  • 3
  • 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 '14 at 02:56

3 Answers3

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.

David Ludwig
  • 1,000
  • 6
  • 9
  • Like a charm! - Compiling in an ubuntu (host) for windows 64 bit (target) with `mingw`, following this tuto http://www.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?? – Xavi Montero Aug 20 '14 at 09:24
  • Yes, the changes were committed to the official, SDL2 repo. – David Ludwig Aug 27 '14 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: https://hg.libsdl.org/SDL/raw-file/e217ed463f25/include/SDL_platform.h – David Ludwig Aug 27 '14 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 07 '16 at 15:32
  • Zsar, I am unable to reproduce your error, using either SDL 2.0.4, or the latest SDL2 code from https://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. – David Ludwig Oct 05 '16 at 20:36
  • I am also having the same issue in when compiling with SDL2 2.0.4 with visual studio 2017 – Sahib Yar Aug 17 '17 at 12:37
  • 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 http://libsdl.org/download-2.0.php – David Ludwig Aug 18 '17 at 17: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!

Neil Regan
  • 153
  • 1
  • 5
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__) */
SeinopSys
  • 8,787
  • 10
  • 62
  • 110
  • I do not have a 'Windows Kits' folder on my C:. Is that a Windows 8 thing? I'm running 64bit Win 7. – user3427293 Mar 17 '14 at 04: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: http://www.marshut.com/irzuki/sdl-platform-h.html – user3427293 Mar 17 '14 at 04:48
  • 1
    Above link is broken – marknuzz Jul 03 '16 at 10:58