GLEW not available in declaration file, but works in header file CMAKE

As stated in the title, I have configured CMake to link GLEW with my project, and have #include <GL/glew.h> in a .hpp file with no issue. The issue arises when trying to use GLEW functions in the declaration (.cpp) file associated with the header file, which gives me the error identifier "xxx" is undefined with xxx being the variety of functions I am trying to use.

Furthermore, I have also linked SDL2 in a similar manner, and have run into no issues in using its functions in the same declaration file. I believe the issue must be in my CMakeLists.txt configuration:

CMakeLists.txt

cmake_minimum_required (VERSION 3.8)

set(PROJECT GUI_Engine)

add_executable (${PROJECT} "./src/driver/main.cpp")

set(HEADER_FILES ./src/include)
set(DEC_FILES ./src/lib)
set(PKGPATH C:/dev/vcpkg/packages)

add_library(engine ${DEC_FILES}/engine.cpp ${HEADER_FILES}/engine.hpp)

list(APPEND CMAKE_PREFIX_PATH ${PKGPATH}/sdl2_x64-windows)
find_package(SDL2 CONFIG REQUIRED)
target_link_libraries(${PROJECT} PRIVATE engine SDL2::SDL2main)
target_link_libraries(engine PUBLIC SDL2::SDL2)

list(APPEND CMAKE_PREFIX_PATH ${PKGPATH}/glew_x64-windows)
find_package(GLEW REQUIRED)
target_link_libraries(engine PUBLIC GLEW::GLEW)

For reference, engine is the label associated with the .hpp and .cpp files I have been referencing.

For further testing, I have tried to #include <GL/glew.h> in my .cpp file, and receive the error cannot open source file "GL/glew.h". Also, when using any GLEW function in my .hpp file, no error arises.

UPDATE My IDE came out with an update today, as well as the associated build tools, with this update, I no longer am having this issue!



Read more here: https://stackoverflow.com/questions/68448070/glew-not-available-in-declaration-file-but-works-in-header-file-cmake

Content Attribution

This content was originally published by Timesis at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: