将 GLEW 与 CMake 联系起来 [英] Linking GLEW with CMake

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

问题描述

如何使用 CMake 将 GLEW 链接到项目?

How can you link GLEW to a project with CMake?

我们一直在尝试使用 CMake 将 GLEW 链接到我们的项目至少 3 小时,但没有任何成功,因此我们接受任何帮助.

We've been trying to link GLEW to our project using CMake for at least 3 hours without any success so any help is accepted.

我正在使用 CMake 3.1.0 附带的 FindGLEW.cmake

I'm using the FindGLEW.cmake which comes with CMake 3.1.0

CMakeLists.txt

find_package(GLEW REQUIRED)
if (GLEW_FOUND)
    include_directories($(GLEW_INCLUDE_DIRS))
endif()

环境变量

我正在使用 MinGW w64 编译源代码,我们成功地将 GLFW 和 GLM 链接起来,只需将包含和库复制到各自的文件夹中,但是在对 GLEW 执行相同操作后,CMake 仍然无法找不到.

I'm using MinGW w64 to compile the sources and we successfully linked GLFW and GLM just by copying the includes and libs to their respective folders, but after doing the same with GLEW, CMake still couldn't find it.

对不起,如果我在制定问题时不够清楚.我将提供所需的任何其他信息.

Sorry if I wasn't clear enough while formulating the question. I will provide any additional information required.

我设法通过在 CMake 缓存文件中指定头文件的位置来链接头文件,尽管我得到了对像 glewInit() 这样的 glew 函数的未定义引用.

I've managed to link the header files by specifying their location in the CMake Cache file, though I'm getting undefined reference to glew functions like glewInit().

推荐答案

FindGLEW 等典型的 CMake 脚本将定义变量,用于指定项目所需的路径和文件.如果脚本无法自动识别正确的路径(通常是因为安装位置不标准,这很好),那么这些变量由您自行填写.

Typical CMake scripts like FindGLEW will define variables that specify the paths and files that your project needs. If the script can't automatically identify the correct paths (usually because of nonstandard install location, which is fine), then it leaves these variables up to you to fill in.

使用命令行 CMake,您可以使用 -D 标志来定义和设置给定变量的值.其他 CMake 接口(例如 CMake-gui 或 IDE 集成)以其他方式为您提供此功能.

With command line CMake, you use the -D flag to define and set the value of a given variable. Other CMake interfaces, like CMake-gui or an IDE integration, give you this ability some other way.

不管你怎么做,你也可以直接修改缓存 (CMakeCache.txt) 并查看 CMake 在那里使用的内容或完全清除缓存.您必须重新运行 CMake 才能获取您的更改.

However you do it, you can also modify the cache directly (CMakeCache.txt) and see what CMake is using in there or just clear the cache altogether. You'll have to rerun CMake for it to pick up your changes.

当涉及到链接时,这就是您需要告诉 CMake 链接哪些库的时候.将 link_libraries 命令与自动化脚本提供的内容结合使用.

When it comes to linking, that's when you need to tell CMake which libs to link. Use the link_libraries command with what the automated script gives you.

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

这篇关于将 GLEW 与 CMake 联系起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆