Search code examples
c++17glewvcpkg

GL/glew.h: no include path set


I am trying to build a glfw and glew c++ code but while building I am getting the following error:

fatal error C1034: GL/glew.h: no include path set

any help is appreciated.

OS: Windows 10

compiler: MSVC++ 17.0.3

package-installer: vcpkg

IDE: Visual Studio Code

Build: Cmake

CmakeLists.txt :

cmake_minimum_required(VERSION 3.0.0)
project(my_project VERSION 0.1.0)

include(CTest)
enable_testing()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_TOOLCHAIN_FILE C:/Users/pc/vcpkg/scripts/buildsystems/vcpkg.cmake)

add_executable(
  my_project
  main.cpp
)

INCLUDE_DIRECTORIES(
  c:/Users/pc/vcpkg/installed/x86-windows/include/
)

LINK_DIRECTORIES(
  c:/Users/pc/vcpkg/installed/x86-windows/lib/
)

find_package(fmt CONFIG REQUIRED)
find_package(GLEW REQUIRED)
find_package(glfw3 REQUIRED)
find_package(freetype CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)

TARGET_LINK_LIBRARIES(my_project
  glfw glm::glm GLEW::GLEW freetype fmt::fmt
)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

Solution

  • Setting CMAKE_TOOLCHAIN_FILE after project(my_project VERSION 0.1.0) does not work since project(my_project VERSION 0.1.0) loads the CMAKE_TOOLCHAIN_FILE. So move it before project()

    Also remove

    INCLUDE_DIRECTORIES(
      c:/Users/pc/vcpkg/installed/x86-windows/include/
    )
    
    LINK_DIRECTORIES(
      c:/Users/pc/vcpkg/installed/x86-windows/lib/
    )
    

    since linking against the above targets should be more than enough! (also always use target_* functions instead.)

    Furthermore increase

    cmake_minimum_required(VERSION 3.0.0)
    

    to something reasonable. You probably don't plan on supporting ancient versions of cmake. If you don't need to support ancient linux distros you can just move to at least 3.17. If you only plan to support windows you can directly move to 3.22 or use whatever vs uses. vcpkg is currently at 3.21.