Adding GLEW to project (CMake)

ぃ、小莉子 提交于 2019-12-05 20:53:17

Your issue is you're forgetting to add the GLEW include directories to your project. You can use target_include_directories or include_directories, the only difference being where you put it in your CMakeLists.txt and the syntax.

I prefer target_include_directories so your CMakeLists.txt after adding it would look like this:

cmake_minimum_required( VERSION 3.5 )

project(Starting)

find_package( OpenGL REQUIRED )

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( ${PROJECT_SOURCE_DIR}/GLEW/build/cmake )
add_subdirectory( ${PROJECT_SOURCE_DIR}/GLFW )

add_executable( Starting ${PROJECT_SOURCE_DIR}/src/main.cxx )
target_include_directories(Starting PRIVATE
    ${PROJECT_SOURCE_DIR}/GLEW/include
)

target_link_libraries( Starting glew32s glfw )

While Julia's suggestion will likely work, there is a find script included with CMake for GLEW, assuming you are using a new enough version, so you should be using that instead of including paths manually. Just add the following:

find_package(GLEW 2.0 REQUIRED)
target_link_libraries(Starting GLEW::GLEW)

This will find GLEW on your system then both link with the necessary libraries and add the necessary include directories.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!