# Cant find SDL.h - Windows, MingW, Cmake and SLD2 (in VSCode with CPP)

**URL:** <https://discourse.libsdl.org/t/cant-find-sdl-h-windows-mingw-cmake-and-sld2-in-vscode-with-cpp/31918>\
**Category:** SDL Development\
**Created:** [June 20, 2021, 5:12pm UTC](https://discourse.libsdl.org/t/cant-find-sdl-h-windows-mingw-cmake-and-sld2-in-vscode-with-cpp/31918 "2021-06-20T17:12:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![BDC\_Patrick](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/bdc_patrick/32/4577_2.png) [@BDC\_Patrick](https://discourse.libsdl.org/u/BDC_Patrick)\
**Post date:** [June 20, 2021, 5:12pm UTC](https://discourse.libsdl.org/t/cant-find-sdl-h-windows-mingw-cmake-and-sld2-in-vscode-with-cpp/31918/1 "2021-06-20T17:12:34Z")

</div>

I stuck with this Problem sind 2 Months now…  
searched myself through Articles, Communities, Boards…etc, and i can´t find any successful Solution to this Problem.

I want to add SDL2 to a Cmake Project, using C++ in VSCode on Windows, but using Mingw64 from Msys2 (g++).

This is my current CMakeLists.txt:

> **CmakeLists.txt**
>
> ```
> cmake_minimum_required(VERSION 3.5)
> 
> project(TileGameStudio_Runtime LANGUAGES CXX)
> 
> set(CMAKE_INCLUDE_CURRENT_DIR ON)
> set(CMAKE_CXX_STANDARD 20)
> set(CMAKE_CXX_STANDARD_REQUIRED ON)
> 
> set(PROJ_SRC
> ${PROJECT_SOURCE_DIR}/src
> )
> 
> add_subdirectory(${PROJECT_SOURCE_DIR}/SDL2)
> include_directories(${PROJECT_SOURCE_DIR}/SDL2/include)
> 
> file(GLOB PROJECT_SOURCES CONFIGURE_DEPENDS
> ${PROJ_SRC}/*.cpp
> )
> 
> set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}\\Game")
> set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}\\Game")
> 
> # add the executable
> add_executable(TileGameStudio_Runtime
> ${PROJECT_SOURCES}
> )
> 
> target_link_libraries(TileGameStudio_Runtime PRIVATE
> SDL2-static
> SDL2main
> )
> 
> set_target_properties(
> TileGameStudio_Runtime
> PROPERTIES
> OUTPUT_NAME "Game"
> SUFFIX ".exe"
> )
> 
> ```

This is my current Project Structure (png image)  
 ![CuProStruc](https://discourse.libsdl.org/uploads/default/original/2X/8/83c833d17a9f52c01c7dbfebcbbdb2e247d3ffca.png)

As you can see. i cloned the Repo from [https://github.com/libsdl-org/SDL](https://github.com/libsdl-org/SDL) as a subdirectory to my Project. And this, i added via cmake add\_subdirectory.

My Main.cpp is simply this:

> **Main.cpp**
>
> ```
> #include <iostream>
> #include <vector>
> #include <string>
> #include <SDL.h>
> 
> #ifdef main
> # undef main
> #endif /* main */
> 
> using namespace std;
> 
> int main(int argc, char *argv[]) {
> SDL_Window *win = NULL;
> SDL_Renderer *renderer = NULL;
> int posX = 100, posY = 100, width = 320, height = 240;
> 
> SDL_Init(SDL_INIT_VIDEO);
> 
> win = SDL_CreateWindow("Hello World", posX, posY, width, height, 0);
> 
> renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
> //================================================ Draw a Text
> //this opens a font style and sets a size
> TTF_Font* Sans = TTF_OpenFont("Sans.ttf", 24);
> // this is the color in rgb format,
> // maxing out all would give you the color white,
> // and it will be your text's color
> SDL_Color White = {255, 255, 255};
> 
> // as TTF_RenderText_Solid could only be used on
> // SDL_Surface then you have to create the surface first
> SDL_Surface* surfaceMessage = TTF_RenderText_Solid(Sans, "put your text here", White); 
> SDL_Texture* Message = SDL_CreateTextureFromSurface(renderer, surfaceMessage);
> SDL_Rect Message_rect; //create a rect
> Message_rect.x = 0; //controls the rect's x coordinate 
> Message_rect.y = 0; // controls the rect's y coordinte
> Message_rect.w = 100; // controls the width of the rect
> Message_rect.h = 100; // controls the height of the rect
> SDL_RenderCopy(renderer, Message, NULL, &Message_rect);
> //================================================ Draw a Text End
> 
> while (1) {
> SDL_Event e;
> if (SDL_PollEvent(&e)) {
> if (e.type == SDL_QUIT) {
> break;
> }
> }
> SDL_RenderClear(renderer);
> SDL_RenderPresent(renderer);
> }
> 
> SDL_DestroyRenderer(renderer);
> SDL_DestroyWindow(win);
> 
> SDL_Quit();
> 
> return 0;
> }
> 
> ```

Which should create a Window… and perhaps draw a text to it.  
But, SDL.h can´t be found… so i can´t build the Stuff here…

Perhaps someone has the same Problem and can help me out here…

---

<div class="post-metadata">

**Author:** ![OKUMURA\_Yuki](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/okumura_yuki/32/2481_2.png) [@OKUMURA\_Yuki](https://discourse.libsdl.org/u/OKUMURA_Yuki)\
**Post date:** [June 21, 2021, 12:34pm UTC](https://discourse.libsdl.org/t/cant-find-sdl-h-windows-mingw-cmake-and-sld2-in-vscode-with-cpp/31918/2 "2021-06-21T12:34:16Z")

</div>

Have you tried to build your project _without_ VSCode?

---

<div class="post-metadata">

**Author:** ![BDC\_Patrick](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/bdc_patrick/32/4577_2.png) [@BDC\_Patrick](https://discourse.libsdl.org/u/BDC_Patrick)\
**Post date:** [June 21, 2021, 2:44pm UTC](https://discourse.libsdl.org/t/cant-find-sdl-h-windows-mingw-cmake-and-sld2-in-vscode-with-cpp/31918/3 "2021-06-21T14:44:32Z")

</div>

Yes, tried to compile with mingw32-make.exe same errors as in vscode, compiling stopped.

---

<div class="post-metadata">

**Author:** ![OKUMURA\_Yuki](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/okumura_yuki/32/2481_2.png) [@OKUMURA\_Yuki](https://discourse.libsdl.org/u/OKUMURA_Yuki)\
**Post date:** [June 21, 2021, 3:19pm UTC](https://discourse.libsdl.org/t/cant-find-sdl-h-windows-mingw-cmake-and-sld2-in-vscode-with-cpp/31918/4 "2021-06-21T15:19:04Z")

</div>

> Yes, tried to compile with mingw32-make.exe same errors as in vscode, compiling stopped.

Nice, what was the error? You can `make VERBOSE=1` to dump command line and copy-pasting it would give some clue to other readers.

In addition you can `set(CMAKE_CXX_FLAGS -v)` to add `-v` flag to the compiler and that will dump which directory was actually searched for the `#include <>` files.

---

<div class="post-metadata">

**Author:** ![BDC\_Patrick](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/bdc_patrick/32/4577_2.png) [@BDC\_Patrick](https://discourse.libsdl.org/u/BDC_Patrick)\
**Post date:** [June 23, 2021, 9:47am UTC](https://discourse.libsdl.org/t/cant-find-sdl-h-windows-mingw-cmake-and-sld2-in-vscode-with-cpp/31918/5 "2021-06-23T09:47:57Z")

</div>

These are the Error Lines…  
As a Pastebin: [https://pastebin.com/rG8JPkMs](https://pastebin.com/rG8JPkMs)

I´m not that into cmd and powershell commands… so i have no experience with VERBOSE or that stuff… Coming from Unity and Unreal… i´m more into IDE compiling stuff, than Shells.

And my IDE (vscode) still can´t find SDL.h. And as a result, it can´t find SDL dependent Stuff…

Here´s my updated CMakeLists.txt, with the cmake VERBOSE enabled:

```
cmake_minimum_required(VERSION 3.5)

project(TileGameStudio_Runtime LANGUAGES CXX)

set(CMAKE_CXX_FLAGS -v)

set(CMAKE_VERBOSE_MAKEFILE ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_CXX_STANDARD 20)

set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(PROJ_SRC

    ${PROJECT_SOURCE_DIR}/src

)

add_subdirectory(${PROJECT_SOURCE_DIR}/SDL2)

include_directories(${PROJECT_SOURCE_DIR}/SDL2/include)

file(GLOB PROJECT_SOURCES CONFIGURE_DEPENDS

    ${PROJ_SRC}/*.cpp

)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}\\Game")

set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}\\Game")

# add the executable

add_executable(TileGameStudio_Runtime

    ${PROJECT_SOURCES}

)

target_link_libraries(TileGameStudio_Runtime PRIVATE

    SDL2-static

    SDL2main

)

set_target_properties(

    TileGameStudio_Runtime

    PROPERTIES

        OUTPUT_NAME "Game"

        SUFFIX ".exe"

)
```

---

<div class="post-metadata">

**Author:** ![OKUMURA\_Yuki](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/okumura_yuki/32/2481_2.png) [@OKUMURA\_Yuki](https://discourse.libsdl.org/u/OKUMURA_Yuki)\
**Post date:** [June 23, 2021, 10:14am UTC](https://discourse.libsdl.org/t/cant-find-sdl-h-windows-mingw-cmake-and-sld2-in-vscode-with-cpp/31918/6 "2021-06-23T10:14:51Z")

</div>

Hmm, your pastebin does not say anything about `<SDL.h>`, the error is

```auto
E:\Game Design\TileGameStudio\TileGameStudio_Runtime\src\Main.cpp:24:5: error: 'TTF_Font' was not declared in this scope
   24 | TTF_Font* Sans = TTF_OpenFont("Sans.ttf", 24);
      | ^ ~~~~~~~

```

These APIs are part of SDL-ttf ( [GitHub - libsdl-org/SDL\_ttf: Support for TrueType (.ttf) font files with Simple Directmedia Layer.](https://github.com/libsdl-org/SDL_ttf) ) so you might want to add it as well to the project. Precompiled development files are available on [https://libsdl.org/projects/SDL\_ttf/](https://libsdl.org/projects/SDL_ttf/) . After correctly added SDL-ttf to the project, [you’ll have to add `#include "SDL_ttf.h"`](https://libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC3).

Aside lacking SDL-ttf, your CMakeLists.txt looks good but I’d recommend to avoid space in the path `E:\Game Design` since using space character inside path string might confuse tools/IDEs.

---

<div class="post-metadata">

**Author:** ![BDC\_Patrick](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/bdc_patrick/32/4577_2.png) [@BDC\_Patrick](https://discourse.libsdl.org/u/BDC_Patrick)\
**Post date:** [June 23, 2021, 10:49am UTC](https://discourse.libsdl.org/t/cant-find-sdl-h-windows-mingw-cmake-and-sld2-in-vscode-with-cpp/31918/7 "2021-06-23T10:49:21Z")

</div>

I commented out the TTF stuff and all, so there is only the SDL.h Error.

I updated my CMakeLists.txt, cause i reinstalled the whole msys2 (since of a installation problem).  
This is the new One:

```
cmake_minimum_required(VERSION 3.5)

project(TileGameStudio_Runtime LANGUAGES CXX)

set(CMAKE_CXX_FLAGS -v)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(PROJ_SRC
    ${PROJECT_SOURCE_DIR}/src
)

file(GLOB PROJECT_SOURCES CONFIGURE_DEPENDS
    ${PROJ_SRC}/*.cpp
)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}\\Game")
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}\\Game")

INCLUDE(FindPkgConfig)
pkg_check_modules(SDL2 REQUIRED sdl2)
pkg_check_modules(SDL2_IMAGE REQUIRED SDL2_image)
pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf)
pkg_check_modules(SDL2_MIXER REQUIRED SDL2_mixer)

include_directories(
    ${SDL2_INCLUDE_DIRS}
    ${SDL2_IMAGE_INCLUDE_DIRS}
    ${SDL2_TTF_INCLUDE_DIRS}
    ${SDL2_MIXER_INCLUDE_DIRS}
)

link_directories (
    ${SDL2_LIBRARY_DIRS}
    ${SDL2_IMAGE_LIBRARY_DIRS}
    ${SDL2_TTF_LIBRARY_DIRS}
    ${SDL2_MIXER_LIBRARY_DIRS}
)

# add the executable
add_executable(TileGameStudio_Runtime
    ${PROJECT_SOURCES}
)

target_link_libraries (TileGameStudio_Runtime 
    ${SDL2_LIBRARIES}
    ${SDL2_IMAGE_LIBRARIES}
    ${SDL2_TTF_LIBRARIES}
    ${SDL2_MIXER_LIBRARIES}
)

set_target_properties(
    TileGameStudio_Runtime
    PROPERTIES
        OUTPUT_NAME "Game"
        SUFFIX ".exe"
)

```

I installed the whole mingw64 toolchain and SDL2 via msys (under MingW64 Mode of msys2) now.

EDIT:  
Changed the Path to “Game\_Design” (without a Space), works now!!  
Thank you very much [OKUMURA\_Yuki](https://discourse.libsdl.org/u/OKUMURA_Yuki)!!!
