GLFW/glfw3.h: No such file or directory

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.

cmake:
cmake_minimum_required(VERSION 3.30.3)
project(cpp)
add_executable(cpp main.cpp)
target_include_directories(cpp PRIVATE dependencies)
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;
}
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

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.

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

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:

$ 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:

[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:

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.

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

I don’t see a single target_link_libraries() 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?

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
this is my project structue.

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.

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.

tried both of them but it didnt work man.

ah, i post my new project on github so check it out GitHub - DPthang411/Opengl

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

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

If you look at your current include statement path and your actual include folder contents, don’t you see what is wrong there?

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