# Can't add GLFW mingw64 static library to CMake project

**URL:** <https://discourse.glfw.org/t/cant-add-glfw-mingw64-static-library-to-cmake-project/2381>\
**Category:** support\
**Created:** [May 16, 2023, 10:23am UTC](https://discourse.glfw.org/t/cant-add-glfw-mingw64-static-library-to-cmake-project/2381 "2023-05-16T10:23:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![OuDret](https://avatars.discourse-cdn.com/v4/letter/o/ea666f/32.png) [@OuDret](https://discourse.glfw.org/u/OuDret)\
**Post date:** [May 16, 2023, 10:23am UTC](https://discourse.glfw.org/t/cant-add-glfw-mingw64-static-library-to-cmake-project/2381/1 "2023-05-16T10:23:10Z")

</div>

Hello,

I’m trying to compile a project to start learning OpenGl, but I can’t.

When I run `CMake -G "Unix Makefiles" ..` it generates the MakeFile without any warning. When running Make, it fails to compile. Here’s the error raised.

```auto
fatal error: GLFW/glfw3.h: No such file or directory
    2 | #include <GLFW/glfw3.h>

```

Here is my `CMakeLists.txt` where I added the library.

```auto
cmake_minimum_required(VERSION 3.9.1)
project(TEST)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

add_library(GLFW STATIC IMPORTED GLOBAL)
set_target_properties(GLFW PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/external/GLFW/libglfw3.a )
set_target_properties(GLFW PROPERTIES INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/external)

add_executable(hello ${CMAKE_SOURCE_DIR}/src/main.cpp)

target_link_libraries(hello GLFW)

```

My project tree:

```auto
root\
      external\
                   GLFW\
                             glfw3.h
                             libglfw3.a
      src\
            main.cpp
      build\
      CMakeLists.txt

```

Do you have any idea of what’s wrong? Thanks ^^’

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [May 16, 2023, 11:55am UTC](https://discourse.glfw.org/t/cant-add-glfw-mingw64-static-library-to-cmake-project/2381/2 "2023-05-16T11:55:51Z")

</div>

It looks like you are setting the include directory on the GLFW target, whereas it should be set on the hello target as this is the one which includes the glfw3.h header. Alternatively I think you can set the [interface\_include\_directories](https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES.html#prop_tgt:INTERFACE_INCLUDE_DIRECTORIES) on the GLFW target and it will be inherited by any target which links with it.

Another approach is to use the [target\_include\_directories](https://cmake.org/cmake/help/latest/command/target_include_directories.html#command:target_include_directories) CMake command instead of `set_target_properties`. This can be inherited if `PUBLIC` by targets which link against the target.

You might also want to check out this [CMake GLFW starter](https://github.com/juliettef/GLFW-CMake-starter) if you just want to get on with learning OpenGL.

---

<div class="post-metadata">

**Author:** ![OuDret](https://avatars.discourse-cdn.com/v4/letter/o/ea666f/32.png) [@OuDret](https://discourse.glfw.org/u/OuDret)\
**Post date:** [May 16, 2023, 12:37pm UTC](https://discourse.glfw.org/t/cant-add-glfw-mingw64-static-library-to-cmake-project/2381/3 "2023-05-16T12:37:41Z")

</div>

Thank you so much. Definetly making GLFW the targe didn’t make sense. Now its targeting what it has to and it’s working

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [May 16, 2023, 12:47pm UTC](https://discourse.glfw.org/t/cant-add-glfw-mingw64-static-library-to-cmake-project/2381/4 "2023-05-16T12:47:53Z")

</div>

Glad to be of help and good luck learning OpenGL.
