Reputation: 19
I'm facing an issue while building my C++ project, and I need some assistance in resolving it. I've set up a project where I manage dependencies using Conan, and I've created a CMakeLists.txt file for linking these libraries. However, when I attempt to build the project using the cmake command, I encounter the following error:
C:/Users/veltr/Desktop/Exercises/OpenGLProject/Application.cpp:1:10: fatal error: GLEW/glew.h: No such file or directory
1 | #include <GLEW/glew.h>
| ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/OpenGLProject.dir/Application.cpp.obj] Błąd 1
make[1]: *** [CMakeFiles/OpenGLProject.dir/all] Błąd 2
I have a conan.txt file where I specify the dependencies to be installed using conan install. I've created a CMakeLists.txt file to link the required libraries. The project seems to build without errors, but I encounter the mentioned fatal error when I try to compile a test code to check the functionality.
conanfile.txt
[requires]
opengl/system
glfw/3.3.8
glew/2.2.0
[generators]
CMakeDeps
CMakeToolchain
[layout]
cmake_layout
CMakeLists.txt
cmake_minimum_required(VERSION 3.27)
project(OpenGLProject)
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
add_executable(${PROJECT_NAME} Application.cpp)
target_link_libraries(${PROJECT_NAME} glfw)
target_link_libraries(${PROJECT_NAME} GLEW::glew_s)
target_link_libraries(${PROJECT_NAME} OpenGL::GL)
Application.cpp
#include <GLEW/glew.h>
#include <GLFW/glfw3.h>
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex2f(-0.5f,-0.5f);
glVertex2f(0.0f, 0.5f);
glVertex2f(0.5f, -0.5f);
glEnd();
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
For example, that the 'fmt' library - by following similar steps - builds and works correctly, and I can use all available #include directives from it. All of the above libraries are available on conan.io, so they should be correct. What am i doing wrong or incorrect?
//EDIT #1 After several attempts to resolve the problem, I couldn't find a solution and ended up making it worse. To get back to the previous state, I had to add absolute paths to the packages downloaded via Conan, as well as the GLEW library I downloaded from the website. Here's my updated CMakeLists.txt:
cmake_minimum_required(VERSION 3.27)
project(OpenGLProject)
# Set the paths to GLFW and OpenGL package configuration files
set(glfw3_DIR "C:/Users/veltr/Desktop/Exercises/OpenGLProject/build/Release/generators")
set(opengl_system_DIR "C:/Users/veltr/Desktop/Exercises/OpenGLProject/build/Release/generators")
# Find and link GLFW
find_package(glfw3 REQUIRED)
# Set the path to GLEW package configuration files
set(GLEW_ROOT "C:/Users/veltr/Downloads/glew-2.1.0-win32/glew-2.1.0")
set(GLEW_INCLUDE_DIRS "${GLEW_ROOT}/include")
set(GLEW_LIBRARIES "${GLEW_ROOT}/lib/Release/Win32/glew32s.lib")
# Find and link GLEW
find_package(GLEW REQUIRED)
# Find and link OpenGL
find_package(OpenGL REQUIRED)
add_executable(${PROJECT_NAME} Application.cpp)
# Link the libraries to your project
target_link_libraries(${PROJECT_NAME} glfw)
target_link_libraries(${PROJECT_NAME} GLEW::GLEW)
target_link_libraries(${PROJECT_NAME} OpenGL::GL)
Now, when I build the project, I get the following output:
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: Target declared 'glfw'
-- Conan: Target declared 'opengl::opengl'
-- Found GLEW: C:/Users/veltr/Downloads/glew-2.1.0-win32/glew-2.1.0/include (found version "2.1.0")
-- Found OpenGL: opengl32
-- Configuring done (3.1s)
-- Generating done (0.1s)
-- Build files have been written to: C:/Users/veltr/Desktop/Exercises/OpenGLProject/build
As you can see, the linker found GLEW, but unfortunately, when I compile the project with make, I still receive the same error.
//EDIT #2
cmake_minimum_required(VERSION 3.27)
project(OpenGLProject)
set(glfw3_DIR "C:/Users/veltr/Desktop/Exercises/OpenGLProject/build/Release/generators")
set(opengl_system_DIR "C:/Users/veltr/Desktop/Exercises/OpenGLProject/build/Release/generators")
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} Application.cpp)
target_link_libraries(${PROJECT_NAME} glfw)
target_link_libraries(${PROJECT_NAME} GLEW::glew_s)
target_link_libraries(${PROJECT_NAME} OpenGL::GL)
output:
(...)
-- Detecting CXX compile features - done
-- Conan: Target declared 'glfw'
-- Conan: Target declared 'opengl::opengl'
-- Found OpenGL: opengl32
CMake Error at C:/Program Files/CMake/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find GLEW (missing: GLEW_INCLUDE_DIRS GLEW_LIBRARIES)
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.27/Modules/FindGLEW.cmake:238 (find_package_handle_standard_args)
CMakeLists.txt:8 (find_package)
(...)
//EDIT #3
cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release ..
seems to build correctly:
(...)
-- Detecting CXX compile features - done
-- Conan: Target declared 'glfw'
-- Conan: Target declared 'opengl::opengl'
-- Found OpenGL: opengl32
-- Conan: Component target declared 'GLEW::glew_s'
-- Conan: Target declared 'GLEW::GLEW'
-- Conan: Target declared 'glu::glu'
-- Configuring done (2.9s)
-- Generating done (0.1s)
but after using make, still got the same error.
//#EDIT 4
cmake_minimum_required(VERSION 3.27)
project(OpenGLProject)
set(glfw3_DIR "C:/Users/veltr/Desktop/Exercises/OpenGLProject/build/Release/generators")
set(opengl_system_DIR "C:/Users/veltr/Desktop/Exercises/OpenGLProject/build/Release/generators")
message(STATUS "GLEW_INCLUDE_DIRS: ${GLEW_INCLUDE_DIRS}")
# Set the path to GLEW (modify this to your actual GLEW directory)
set(GLEW_ROOT "C:/Users/veltr/Downloads/glew-2.1.0-win32/glew-2.1.0")
# Provide hints for GLEW using CMAKE_PREFIX_PATH
set(CMAKE_PREFIX_PATH "${GLEW_ROOT};${CMAKE_PREFIX_PATH}")
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
add_executable(${PROJECT_NAME} Application.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC ${GLEW_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} glfw)
target_link_libraries(${PROJECT_NAME} OpenGL::GL)
target_link_libraries(${PROJECT_NAME} GLEW::GLEW)
#cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release ..
i had to manually install glew lib from thier site and set correct paths. In application.cpp i changed #include <GLEW/glew.h>
to #include <GL/glew.h>
and everything seems to be working. How can i make more generic Cmake and avoid hardcoding paths?
Upvotes: 0
Views: 1481
Reputation: 1
I think the issue is that you're not properly including the GLEW headers in your Conan workspace.
When you install dependencies with Conan, the header files are not automatically made available to your project. You have a few options to fix this:
Add the GLEW include directory to your CMakeLists.txt:
# After find_package(GLEW ...)
include_directories(${GLEW_INCLUDE_DIRS})
Add the GLEW include directory to your C++ compiler include paths:
add_executable(${PROJECT_NAME} Application.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC ${GLEW_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ...)
Use the conan_basic_setup() CMake macro to set up all the include directories for you:
include(conanbuildinfo.cmake)
conan_basic_setup()
add_executable(${PROJECT_NAME} Application.cpp)
target_link_libraries(${PROJECT_NAME} ...)
Upvotes: 0