[英]GLFW directory not found with CMake and vcpkg
I have been unable to figure out how to get CMake to find and set correct GLFW CMake constants when using CMake in VS2017. 我无法弄清楚在VS2017中使用CMake时如何使CMake查找并设置正确的GLFW CMake常数。 Any help will be greatly appreciated :).
任何帮助将不胜感激 :)。
I downloaded glfw3
through Microsoft's vcpkg
tool. 我通过Microsoft的
vcpkg
工具下载了glfw3
。 I have checked that files do physically exist in the directory that vcpkg
puts them in ( ~\\vcpkg\\installed\\x86-windows\\include
). 我检查过文件是否确实存在于
vcpkg
放置它们的目录中( ~\\vcpkg\\installed\\x86-windows\\include
)。 I set up my CMakeSettings.json
as per their docs here . 我根据这里的文档设置了
CMakeSettings.json
。 I used that tutorial as a basis for getting GLFW to be set up correctly. 我以该教程为基础来正确设置GLFW。
I then use find_package(glfw3 REQUIRED)
to find the glfw3
library. 然后,我使用
find_package(glfw3 REQUIRED)
查找glfw3
库。 This does not spit out any errors. 这不会吐出任何错误。 Actually the
CMakeLists.txt
doesn't complain at all. 实际上,
CMakeLists.txt
根本没有抱怨。 It's at the compile stage where it complains. 它在编译阶段抱怨。
After that I add glfw3
with target_link_libraries(exe ${GLFW3_LIBRARIES})
to the executable. 之后,我将
glfw3
target_link_libraries(exe ${GLFW3_LIBRARIES})
添加到可执行文件中。
Then when I try and build a simple example (including the header file), the compilation fails because it cannot find GLFW/glfw3.h
. 然后,当我尝试构建一个简单的示例(包括头文件)时,编译失败,因为找不到
GLFW/glfw3.h
。
The error from MSVC: 来自MSVC的错误:
fatal error C1083: Cannot open include file: 'GLFW/glfw3.h': No such file or directory
Here is my CMakeLists.txt
for added reference: 这是我的
CMakeLists.txt
供参考:
cmake_minimum_required(VERSION 3.7)
project(learn-opengl)
find_package(glfw3 REQUIRED)
add_executable(learn-opengl main.cpp)
target_link_libraries(learn-opengl ${GLFW3_LIBRARIES})
GLFW3_LIBRARIES
I got from glfw3Config.cmake
by snooping around what vcpkg
puts in the installed directory ( ~\\vcpkg\\installed\\x86-windows\\share\\glfw3
) 我从
glfw3Config.cmake
GLFW3_LIBRARIES
了glfw3Config.cmake
是窥探一下vcpkg
在已安装目录中的位置( ~\\vcpkg\\installed\\x86-windows\\share\\glfw3
)
And just in case, the main.cpp
: 以防万一,
main.cpp
:
#include <GLFW/glfw3.h>
int main()
{
return 0;
}
I have tried calling cmake
from the command line as well, but to no avail that didn't work either. 我也尝试过从命令行调用
cmake
,但无济于事。
Am I missing something? 我想念什么吗? Did I perhaps misunderstand something in
vcpkg
documentation? 我是否可能会误解
vcpkg
文档中的vcpkg
内容? I have really no idea what I am missing... :/ I should say, in addition, that I am fairly new to CMake as well. 我真的不知道我缺少什么...:/另外,我应该说我对CMake也很陌生。
Reformulating my previous comment as answer: 重新整理我以前的评论作为答案:
You should add the imported target glfw
to your target_link_libraries
command instead of ${GLFW3_LIBRARIES}
. 您应该添加导入目标
glfw
您target_link_libraries
命令,而不是${GLFW3_LIBRARIES}
。 The find_package(glfw3)
generates an import target glfw
. find_package(glfw3)
生成导入目标glfw
。 By making your target learn-opengl
dependent on this imported target you specify both the library to link with and the include directories to use. 通过使目标
learn-opengl
依赖于此导入的目标,可以指定要链接的库和要使用的包含目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.