#include <glad/glad.h>: No such file or directory (even though source and header are in the same directory)

briguyjm picture briguyjm · Feb 24, 2017 · Viewed 12.7k times · Source

I recently started converting a game engine I wrote in Java (using lwjgl) to C/C++. I am using Qt Creator and CMake on Fedora 25 (I'm pretty sure this doesn't affect anything) to link all the directories, files, etc. GLFW is installed on my system, but I decided to use the source version, rather than the included version. I am using glad for my extension loader, and configured it following the tutorial on the GLFW website. I haven't gotten past the "Hello World" test because when I include the glad.h file in my main.c file, I get an error:

<glad/glad.h>: No such file or directory

What is equally strange is that I get this same error in the glad.c file, the one that was created using glad's own generator. My main.c file looks like this

#include <stdio.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>

int main(int argc, char *argv[])
{
    printf("Kick Ass Game Engine");
    return 0;
}

I have also tried using "glad.h: instead of <glad/glad.h> (I found that suggestion here). This did work for my main.c file, but I still have the same issue with the glad.c file, even after I edited it to reflect main.c.

My project directory looks like this:

- KAGE/
  -> CMakeLists.txt
  -> glad.c
  -> glad.h
  -> main.c
  -> khplatform.h
-> KAGE/lib/
   -> glad
   -> glfw-3.2.1

As you can see, all of my .c and their header files are in one directory. The lib directory is where I keep glad and glfw. I just copied the files from the lib/glad directory to the main project one.

My CMake looks like this

project(KAGE)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})

set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

add_subdirectory(/home/brian/KAGE/lib/glfw-3.2.1)

find_package(OpenGL REQUIRED)

target_link_libraries(KAGE glfw)

I have tried searching around, but all of the issues people had where when trying to call libraries installed on the system. Mine are not installed. I have a separate directory (lib) where I keep everything I use. The only solution I found that came close to what I was looking for was the one about replacing <glad/glad.h> with "glad.h". As I said earlier, this did not work. The tutorial on GLFW's website does not offer any other information or troubleshooting.

Any help or suggestions is greatly appreciated. Thank you.

Answer

John3136 picture John3136 · Feb 24, 2017

Seems glad.h is not in a directory called glad, so including it via glad/glad.h is just never going to work!

If you on linux one trick is make a softlink to . called glad and then you can have glad/glad/glad/glad/glad.h if you want it.

Better solution is to install stuff properly so files end up at their expected paths...