0

VS Code keeps displaying an error: fatal error: SDL2/SDL_image.h: No such file or directory

This is my code:

#include <iostream>
#include <SDL2/SDL.h>

const int WIDTH = 800, HEIGHT = 600;

int main( int argc, char *argv[] )
{
    SDL_Init( SDL_INIT_EVERYTHING );

    SDL_Window *window = SDL_CreateWindow( "Hello SDL WORLD", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_ALLOW_HIGHDPI );

    if ( NULL == window )
    {
        std::cout << "Could not create window: " << SDL_GetError( ) << std::endl;
        return 1;
    }

    SDL_Event windowEvent;

    while ( true )
    {
        if ( SDL_PollEvent( &windowEvent ) )
        {
            if ( SDL_QUIT == windowEvent.type )
            { break; }
        }
    }

    SDL_DestroyWindow( window );
    SDL_Quit( );

    return EXIT_SUCCESS;
}

HOWEVER, if I use makefile, instead of using the compile button it magically works...

I want to use Debbuger, however I'm unable to do so due to this error

genpfault
  • 51,148
  • 11
  • 85
  • 139
MrRooby
  • 9
  • 1
  • You need to find out where SDL include files (and libs) are installed. How did you instal SDL? The `Makefile` must have the correct paths in it. – wcochran Jun 04 '23 at 00:26
  • There is also value in simply opening up a terminal and compiling by hand. There is no doubt what is being supplied to the compiler that way. Once you have it working on the command line, you will have all the information you need to tell VSCode how to configure itself. – David C. Rankin Jun 04 '23 at 04:32

1 Answers1

1

The reason MakeFile build works is because include paths and other info is set correctly, but vscode doesn't know about that.

You can use the MakeFile Tools extension. It provides info from MakeFile directly to vscode. This allows vscode in intellisense, compilation, debugging and lot more.

You will also find info on how to setup debugging in the Getting Started section.

Chetan
  • 11
  • 1
  • 1