将GLEW与CMake链接 [英] Linking GLEW with CMake
问题描述
如何将GLEW连结至CMake的专案?
我们一直尝试使用CMake将GLEW连结至我们的专案至少3小时,所以任何帮助被接受。
我正在使用CMake 3.1.0附带的FindGLEW.cmake
CMakeLists。 txt
find_package(GLEW REQUIRED)
if(GLEW_FOUND)
include_directories GLEW_INCLUDE_DIRS))
endif()
环境变量 p>
我使用 MinGW w64 来编译源代码,我们通过将include和libs复制到各自的文件夹,成功地链接了GLFW和GLM,但是在使用GLEW执行相同操作之后,CMake仍然找不到它。
对不起,如果我在阐述问题时还不够清楚。我将提供所需的任何其他信息。
编辑:我已经设法链接头文件, CMake Cache文件,虽然我得到未定义的引用glew函数像 glewInit()
。
典型的CMake脚本如FindGLEW将定义变量,指定项目需要的路径和文件。如果脚本不能自动识别正确的路径(通常是因为非标准的安装位置,这是罚款),那么这些变量让你填写。
使用命令行CMake,可以使用-D标志来定义和设置给定变量的值。其他CMake接口,像CMake-gui或IDE集成,给你这种能力一些其他的方式。
但你这样做,你也可以直接修改缓存.txt),看看CMake在里面使用什么或者完全清除缓存。你必须重新运行CMake来获取你的更改。
当涉及到链接,这是当你需要告诉CMake哪些libs链接。使用 link_libraries
命令和自动化脚本提供的命令。
find_package (GLEW REQUIRED)
if(GLEW_FOUND)
include_directories($ {GLEW_INCLUDE_DIRS})
link_libaries($ {GLEW_LIBRARIES})
endif()
How can you link GLEW to a project with CMake?
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.
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()
Environment Variables
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.
Edit: 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()
.
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.
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.
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.
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)
if (GLEW_FOUND)
include_directories(${GLEW_INCLUDE_DIRS})
link_libraries(${GLEW_LIBRARIES})
endif()
这篇关于将GLEW与CMake链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!