本文介绍了CMake找不到GLEW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读过[1],但就我而言,CMake说它找不到毛病.

I've read this [1], but in my case CMake says it can't find glew.

我在Windows上,并且我的CMake模块文件夹中有一个FindGLEW.cmake文件,大概是在我安装CMake-3.6时放置的位置.我在sourceforge上找到了GLEW,并下载了Windows的zip文件.我解压缩并安装在C:\ Program Files \ glew中.当我创建了自己的库并使用CMake构建和安装它们时,这是它们安装的默认位置,因此我非常有信心在这里可以.

I'm on Windows and there is a FindGLEW.cmake file in my CMake modules folder, presumably put there when I installed CMake-3.6. I found GLEW on sourceforge and downloaded the zip file for Windows. I unzipped and installed in C:\Program Files\glew. When I've created my own libraries and used CMake to build and install them, this is the default location they are installed to so I am pretty confident I'm OK here.

我的CMakeLists.txt中的代码段是:

The snippet from my CMakeLists.txt is:

find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})
link_libraries(${GLEW_LIBRARIES})

CMake的实际错误消息是:

The actual error message from CMake is:

CMake Error at C:/Program Files/CMake/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find GLEW (missing: GLEW_INCLUDE_DIR GLEW_LIBRARY)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files/CMake/share/cmake-3.6/Modules/FindGLEW.cmake:44 (find_package_handle_standard_args)
  source/CMakeLists.txt:5 (find_package)

FindGLEW.cmake是否可能损坏?我查看了另外两个FindXXXXX.cmake文件,它们就像雪花一样,每个雪花都很独特.因此,很难确定我是否遵循惯例.

Is it possible the FindGLEW.cmake is broken? I've looked at a couple of other FindXXXXX.cmake files and they are like snowflakes, each one pretty unique. So it's hard for me to say with any certainty that it's following convention.

[1] 将GLEW与CMake关联

推荐答案

查看来源,该程序包正在相对路径中寻找GLEW.使用不同的前缀(包括变量CMAKE_PREFIX_PATH:

Looking in the sources, the package is looking for GLEW in relative paths. These relative paths are searched using different prefixes, including the content of the variable CMAKE_PREFIX_PATH:

  • <prefix>/include,用于查找包含目录.
  • <prefix>/lib表示find_library,用于查找库.
  • <prefix>/include for find_path which is used to find include directories.
  • <prefix>/lib for find_library which is used to find libraries.

假设存在C:/Program Files/glew/include和C:/Program Files/glew/lib,请将C:/Program Files/glew添加到您的CMAKE_PREFIX_PATH变量中.像这样:

Assuming C:/Program Files/glew/include and C:/Program Files/glew/lib exist, add C:/Program Files/glew to your CMAKE_PREFIX_PATH variable. Something like:

list(APPEND CMAKE_PREFIX_PATH "C:/Program Files/glew")
find_package(GLEW REQUIRED)

请注意以下几行:

include_directories(${GLEW_INCLUDE_DIRS})
link_libraries(${GLEW_LIBRARIES})

可以使用导入的目标

may be dropped using imported target Glew::Glew:

add_executable(foo ...)
target_link_libraries(foo Glew::Glew)

这篇关于CMake找不到GLEW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!