问题描述
我想将glfw和glew链接到我的图形编程项目.
I want to link glfw and glew to my project for graphics programming.
添加glfw非常简单,我按照他们网站上的说明进行操作.用glfw创建一个窗口效果很好.
Adding glfw was pretty straight forward, I followed the instructions on their website. Creating a window with glfw worked perfectly.
但是,我看不到添加GLEW的CMakeLists.txt有什么问题.程序给出错误:"GL/glew.h:没有这样的文件或目录".
However, I can't see what's wrong with my CMakeLists.txt for adding GLEW. The program gives the error: "GL/glew.h: No such file or directory".
我的CMakeLists.txt:
My CMakeLists.txt:
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_link_libraries( Starting glew32s glfw )
我尝试给它命名为GLEW,glew,glew32,但没有任何变化.该库可从此处下载: https://github.com/Perlmint/glew-cmake
I've tried giving it the names GLEW, glew, glew32 instead but nothing changed.The library is downloaded from here: https://github.com/Perlmint/glew-cmake
如果有任何重要性,这是我运行CMakeLists.txt的批处理文件(位于项目源目录中的构建文件夹中):
If it has any importance, this is the batch file with which I run my CMakeLists.txt (located in a build folder inside my project source directory):
@echo off
cmake -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
make all
在github上查看OpenGL项目并没有帮助,因为几乎所有项目都使用Visual Studio.如果有人能告诉我我做错了,那就太好了.
Looking at OpenGL projects on github didn't help since almost all of them are using visual studio.It would be great if someone could tell me what I got wrong.
推荐答案
虽然Julia的建议可能会起作用,但是CMake for GLEW附带了一个查找脚本,假设您使用的是足够新的版本,那么您应该使用该脚本而不是手动包含路径.只需添加以下内容:
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)
这将在您的系统上找到GLEW,然后链接到必要的库并添加必要的包含目录.
This will find GLEW on your system then both link with the necessary libraries and add the necessary include directories.
这篇关于将GLEW添加到项目(CMake)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!