# GLFW/glfw3.h: No such file or directory

**URL:** <https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591>\
**Category:** Code\
**Created:** [September 5, 2024, 1:57pm UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591 "2024-09-05T13:57:59Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ph_c_th_ng_dinh/32/4906_2.png) [@Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/u/Ph_c_Th_ng_Dinh)\
**Post date:** [September 5, 2024, 1:57pm UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/1 "2024-09-05T13:57:59Z")

</div>

I am trying to learn glfw and opengl but I got the error that i mentioned on the title that is no such file or directory.

```auto
cmake:
cmake_minimum_required(VERSION 3.30.3)
project(cpp)
add_executable(cpp main.cpp)
target_include_directories(cpp PRIVATE dependencies)

```

```auto
cpp
#include <iostream>
#include <GLFW/glfw3.h>
using namespace std;
int main(){
    GLFWwindow* window;
    while (!glfwInit){
        cout << "hello";
    }
    window = glfwCreateWindow(800, 400, "hello", NULL, NULL);
    return 0;
}

```

```auto
cpp/
│
├── .vscode/
│ ├── launch.json
│ ├── tasks.json
│
├── build/
│ ├── CMakeFiles/
│ ├── cmake_install.cmake
│ ├── CMakeCache.txt
│ ├── compile_commands.json
│
├── Makefile
│
├── dependencies/
│ ├── GLFW/
│ ├── glfw3.h
│ ├── glfw3native.h
│
├── CMakeLists.txt
├── main.cpp
└── main.exe

```

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [September 8, 2024, 9:26am UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/2 "2024-09-08T09:26:07Z")

</div>

Looking at what you have here, I’d say that GLFW headers should have been discovered, so I got curious and tried to reproduce your problem, but I could not (_with CMake `3.29.2`_). The project of course fails on linking, because you are missing linking to GLFW binary, but I did not get your error about the header.

So it is probably something environmental, such as you are on a case-sensitive filesystem, and your GLFW headers folder is actually named `glfw`.

If you want, I could try to reproduce it with your exact project files, so if you’d be interested in that, share an archive or repository here.

---

<div class="post-metadata">

**Author:** ![Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ph_c_th_ng_dinh/32/4906_2.png) [@Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/u/Ph_c_Th_ng_Dinh)\
**Post date:** [September 11, 2024, 3:11pm UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/3 "2024-09-11T15:11:56Z")

</div>

> **[GitHub - DPthang411/OpenglLearning at master](https://github.com/DPthang411/OpenglLearning/tree/master)**
>
> master

this is the link to my project! Have a llok at it to see the details. I am bad at explaining.

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [September 11, 2024, 7:05pm UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/4 "2024-09-11T19:05:04Z")

</div>

Okay, I tried to reproduce the headers problem with the project from your repository, but it’s the same as the one that I tried to re-create based on your original description, so I did not get that error still.

Just in case, here are the commands that I executed:

```sh
$ git clone git@github.com:DPthang411/OpenglLearning.git
$ cd ./OpenglLearning/
$ git switch master
$ cd ./build/
$ rm -r ./*; rm -r .cmake; ls -lah
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..
$ cmake --build .

```

and that resulted in:

```sh
[2/2] Linking CXX executable cpp
FAILED: cpp
Undefined symbols for architecture arm64:
  "_glfwCreateWindow", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture arm64

```

Like I already said, the linking error is expected, because you don’t link to GLFW in your project. But why you get the headers error - that I don’t understand. The only difference I can immediately see between our environments is that I’m on Mac OS and you seem to be on Windows (_with MSYS/MinGW?_), although that shouldn’t matter.

Just in case, I tried on Windows too, but got the same result:

```auto
main.cpp.obj : error LNK2019: unresolved external symbol glfwCreateWindow referenced in function main
cpp.exe : fatal error LNK1120: 1 unresolved externals

```

No error about headers.

---

<div class="post-metadata">

**Author:** ![Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ph_c_th_ng_dinh/32/4906_2.png) [@Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/u/Ph_c_Th_ng_Dinh)\
**Post date:** [September 13, 2024, 12:51pm UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/5 "2024-09-13T12:51:10Z")

</div>

wdym by i didnt libk it? i linked it using cmake?

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [September 13, 2024, 12:54pm UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/6 "2024-09-13T12:54:21Z")

</div>

I don’t see a single [target\_link\_libraries()](https://cmake.org/cmake/help/latest/command/target_link_libraries.html) in your project.  
So then what do you mean by “_i linked it_”? Can you show the exact line/fragment which you think does the linking in your project?

---

<div class="post-metadata">

**Author:** ![Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ph_c_th_ng_dinh/32/4906_2.png) [@Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/u/Ph_c_Th_ng_Dinh)\
**Post date:** [September 26, 2024, 2:10pm UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/7 "2024-09-26T14:10:13Z")

</div>

cmake\_minimum\_required(VERSION 3.30.3)

project(cpp)

add\_executable(cpp main.cpp)

include\_directories(libraries/glfw3/include)

target\_link\_libraries(cpp libraries/glfw3/lib-mingw-w64/libglfw3.a)

here is my new cmake but I still get the same errors. Why?  
 ![image](https://discourse.cmake.org/uploads/default/original/2X/a/a90fc5637b6922560e25cd2b882339b7f37e41c0.png)  
this is my project structue.

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [September 26, 2024, 2:16pm UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/8 "2024-09-26T14:16:56Z")

</div>

> [@Ph\_c\_Th\_ng\_Dinh](#):
>
> still get the same errors

If you mean your original error about missing header - like I said, that problem I could not reproduce, so I can’t say what could be causing it on your side. Maybe someone else can.

---

<div class="post-metadata">

**Author:** ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)\
**Post date:** [September 27, 2024, 6:27am UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/9 "2024-09-27T06:27:21Z")

</div>

I think this is because you’re doing `include_directories(libraries/glfw3/include)` after `add_executable(cpp main.cpp)`.

Either swap the the lines, or use `target_include_directories(cpp PRIVATE libraries/glfw3/include)` instead.

---

<div class="post-metadata">

**Author:** ![Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ph_c_th_ng_dinh/32/4906_2.png) [@Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/u/Ph_c_Th_ng_Dinh)\
**Post date:** [September 29, 2024, 4:52am UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/10 "2024-09-29T04:52:26Z")

</div>

tried both of them but it didnt work man.

---

<div class="post-metadata">

**Author:** ![Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ph_c_th_ng_dinh/32/4906_2.png) [@Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/u/Ph_c_Th_ng_Dinh)\
**Post date:** [September 29, 2024, 5:36am UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/11 "2024-09-29T05:36:58Z")

</div>

ah, i post my new project on github so check it out [GitHub - DPthang411/Opengl](https://github.com/DPthang411/Opengl)

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [September 29, 2024, 8:03pm UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/12 "2024-09-29T20:03:44Z")

</div>

In this new project of yours I see that the path is clearly wrong, which would indeed result in that error about the header.

---

<div class="post-metadata">

**Author:** ![Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ph_c_th_ng_dinh/32/4906_2.png) [@Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/u/Ph_c_Th_ng_Dinh)\
**Post date:** [October 4, 2024, 1:33pm UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/13 "2024-10-04T13:33:06Z")

</div>

changed but the error still appeared with his brothers which are more errors

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [October 4, 2024, 2:07pm UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/14 "2024-10-04T14:07:12Z")

</div>

If you look at your current [include statement](https://github.com/DPthang411/Opengl/blob/cc03b4f1e35579c6f2d0a65a53d7d624655ece78/main.cpp#L1) path and your actual [include folder](https://github.com/DPthang411/Opengl/tree/cc03b4f1e35579c6f2d0a65a53d7d624655ece78/libraries/glfw3/include) contents, don’t you see what is wrong there?

---

<div class="post-metadata">

**Author:** ![Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ph_c_th_ng_dinh/32/4906_2.png) [@Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/u/Ph_c_Th_ng_Dinh)\
**Post date:** [October 6, 2024, 12:51am UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/15 "2024-10-06T00:51:30Z")

</div>

whats that? Thats all the stuffs appeared in glfw3/include folder when i installed it?

---

<div class="post-metadata">

**Author:** ![neel\_vadher](https://discourse.cmake.org/user_avatar/discourse.cmake.org/neel_vadher/32/5655_2.png) [@neel\_vadher](https://discourse.cmake.org/u/neel_vadher)\
**Post date:** [July 7, 2025, 9:17pm UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/16 "2025-07-07T21:17:31Z")

</div>

got any solution?..i started learning opengl too and getting the same issues…i tried everything but nothing works!

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [July 7, 2025, 10:22pm UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591/17 "2025-07-07T22:22:20Z")

</div>

The solution was to have correct paths in the project’s `CMakeLists.txt`.

How does your project look like, how did you install/download/build GLFW?
