0

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.

Community
  • 1
  • 1
briguyjm
  • 43
  • 1
  • 3
  • 12

4 Answers4

3

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...

John3136
  • 28,809
  • 4
  • 51
  • 69
  • Creating a `glad` directory did not work. I still have the same issue. I also installed glad according to the glad website. It is just used to generate the header files, and doesn't require any special install directories aside from the one `pip` uses. And since glfw has no issues with the way I set it up, I don't see how not having a glad directory is the issue. The glfw website also said to just take the files glad generates and place them in the project's root directory. – briguyjm Feb 24 '17 at 04:32
1

CMake doesn't include current directory by default. For enable this behavior you need to set CMAKE_INCLUDE_CURRENT_DIR variable:

set(CMAKE_INCLUDE_CURRENT_DIR ON)

After that for including the header your glad.c file may use

#include "glad.h"
Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • This worked. I also had to change the `glad.c` file to use `#include "glad.h"` along with my `main.c`. Thank you. Do you have any idea as to why the `#include` didn't work before? It gave me the same error in the `glad.c` file, but had no issue with `#include `, even though they are both set up the same way in the project directory. – briguyjm Feb 25 '17 at 01:37
  • When you use `#include ` you ask compiler for find specified **relative path** in one of *include directories*. As none of your directory contains this relative path, compiler cannot find it. Also, include directories should be specified with `include_directories()` command in CMake. This is done by GLFW when you perform `add_subdirectory()` for build this library. – Tsyvarev Feb 25 '17 at 18:54
1

Today I met the same problem and found this posting. I use vcpkg to manage my pkg. I can be sure that the path of the file is right,but it do not work. And magically,when I delete #include <glad/glad.h> and reenter it,it works.

yunqi luo
  • 21
  • 1
  • 1
    Are you sure, that when you "reentered" the include line, it was actually the same? – T S Mar 22 '21 at 14:48
0

If glad folder is in the project root directory, means:

KAGE
  glad

then the Cmakelist for glad:

# glad
set(GLAD_DIR "${LIB_DIR}glad")
add_library("glad" "${GLAD_DIR}/src/glad.c")
target_include_directories("glad" PRIVATE "${GLAD_DIR}/include")
target_include_directories(${PROJECT_NAME} PRIVATE "${GLAD_DIR}/include")
target_link_libraries(${PROJECT_NAME} "glad" "${CMAKE_DL_LIBS}")

if it's in a lib directory

KAGE
  lib
    glad

then change cmkaelist: from set(GLAD_DIR "${LIB_DIR}glad") to set(GLAD_DIR "${LIB_DIR}lib/glad")