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

user3427293 picture user3427293 · Mar 17, 2014 · Viewed 52.9k times · Source

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;
}

Answer

David Ludwig picture David Ludwig · Mar 24, 2014

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.