Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

game.h no such file or directory when using SDL with VScode

So, I am learning SDL 2 and using it with vscode, this is my file structure

file structure

in the miain.cpp file this is my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#include <game.h>

int main(int argc, char* argv[]){
    int screenWidth = 1024;
    int screenHight = 600;
    Game game("Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenWidth, screenHight, SDL_WINDOW_SHOWN);
    while(game.gameState != GameState::EXIT){
        SDL_Event evnt;
        SDL_PollEvent(&evnt);
        switch (evnt.type){
            case SDL_QUIT:
                game.gameState = GameState::EXIT;
                break;
            
            default:
                break;
        }        
    };
    return 0;
}

when I compile I get this error:
fatal error: game.h: No such file or directory

>Solution :

The problem is not VSCode but the project folding structure. You are trying to import a file using a wrong path. The correct one is #include <../headers/game.h>.

I suggest you to move main.cpp in the root project directory and game.h file path will be #include <include/headers/game.h>.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading