I want to make a simple game using C++ & GLFW.
I included the library using CMake as follows:
cmake_minimum_required(VERSION 3.15.3)
set(CMAKE_CXX_STANDART 20)
project(tetris_game)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(PkgConfig)
pkg_check_modules(opengl REQUIRED gl)
add_subdirectory(${PROJECT_SOURCE_DIR}/libs/glfw3)
add_executable(tetris ./src/main.cpp)
target_link_libraries(tetris ${opengl_LIBRARIES} glfw)
target_include_directories(tetris PUBLIC ${opengl_INCLUDE_DIRS})
target_compile_options(tetris PUBLIC ${opengl_CFLAGS_OTHER})
Without the glad/gl.h
header file, OpenGL works fine. I successfully open a window using OpenGL, but when I include that header, the error occurs:
fatal error: glad/gl.h: No such file or directory
My directory structure as follows:
.
├── CMakeLists.txt
├── builds
├ ├── more files.
├
├-- libs
├ ├-- glfw3
├ ├ ├-- deps
├ ├ ├ ├-- glad
├ ├ ├ ├ ├-- gl.h
├ ├ ├ ├
├ ├ ├ ├-- glad_gl.c
...
I tried this solution:
instead of
add_executable(tetris ./src/main.cpp)
I use
add_executable(tetris ./src/main.cpp ${PROJECT_SOURCE_DIR}/libs/glfw3/deps/glad/gl.h ${PROJECT_SOURCE_DIR}/libs/glfw3/deps/glad_gl.c)
but did not work.
I just added this two lines to CMakeLists.txt
include_directories(${PROJECT_SOURCE_DIR}/libs/glfw3/deps/)
add_executable(tetris ./src/main.cpp ${PROJECT_SOURCE_DIR}/libs/glfw3/deps/glad_gl.c)
Now, OpenGL is working.