【发布时间】:2019-03-16 20:59:52
【问题描述】:
对于使用 vcpkg 安装的软件包,我很难找到要在 cmake 文件中使用的正确“库目标名称”。
例如,我使用vcpkg install gtest 安装了gtest 包。我的示例 cmake 文件如下所示:
#CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(example)
add_executable(main main.cpp)
find_package(gtest REQUIRED)
target_link_libraries(main gtest) # here, "gtest" is not the right name!
运行cmake,生成Visual Studio的解决方案,但运行cmake --build .后,报错:
../use-cmake-vcpkg\main.cpp(1): fatal error C1083: Cannot open include file: 'gtest/gtest.h': No such file or directory ..
原来这行:target_link_libraries(main gtest) 不正确,我需要使用另一个“名称”来包含/链接 gtest 包。
有没有办法(使用 cmake 或 vcpkg)找出要使用的正确目标名称是什么? (在这种情况下适用于 gtest,但也适用于任何其他包装?)
【问题讨论】: