'Compiler can't find SDL2 classes. How to properly include and link them?

I just started venturing into C++. I download this simple helicopter game and I'm trying to compile it, but I don't know how to properly include and link the SDL2 dependencies.

My first approach was trying to compile it with gcc. I got to the following command:

gcc main.cpp ^
-I C:\code\SDL2\SDL2-2.0.22\include ^
-I C:\code\SDL2\SDL2_image-2.0.5\include ^
-I C:\code\SDL2\SDL2_mixer-2.0.4\include ^
-I C:\code\SDL2\SDL2_ttf-2.0.18\include ^
-L C:\code\SDL2\SDL2-2.0.22\lib\x64 ^
-L C:\code\SDL2\SDL2_image-2.0.5\lib\x64 ^
-L C:\code\SDL2\SDL2_mixer-2.0.4\lib\x64 ^
-L C:\code\SDL2\SDL2_ttf-2.0.18\lib\x64

But the compiler complains about not being able to find classes and functions from the SDL2 libs. For instance, the first of the many errors it gives is

In file included from heli.h:4:0,
                 from main.cpp:7:
loader.h: In function 'SDL_Surface* load_image(std::__cxx11::string, int)':
loader.h:27:57: error: 'SDL_DisplayFormat' was not declared in this scope
         optimizedImage = SDL_DisplayFormat( loadedImage );

I then tried to turn the code base into a Visual Studio project and configured it following this tutorial, basically having the following configuration:

  • Include Directories:

    C:\code\SDL2\SDL2-2.0.22\include;C:\code\SDL2\SDL2_image-2.0.5\include;C:\code\SDL2\SDL2_mixer-2.0.4\include;C:\code\SDL2\SDL2_ttf-2.0.18\include;$(IncludePath)

  • Library Directories:

    C:\code\SDL2\SDL2-2.0.22\lib\x64;C:\code\SDL2\SDL2_image-2.0.5\lib\x64;C:\code\SDL2\SDL2_mixer-2.0.4\lib\x64;C:\code\SDL2\SDL2_ttf-2.0.18\lib\x64;$(LibraryPath)

  • Linker/Input/Additional Dependencies:

    SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib;SDL2_ttf.lib;%(AdditionalDependencies)

But then I got the exact same missing dependencies, as "identifier 'foo' not found" or "'bar': undeclared identifier". What am I missing about including and linking C++ dependencies?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source