cmake - 无法在 CLion 中使用与 VCPKG 一起安装的库

标签 cmake clion vcpkg openmesh

我遵循了 VCPKG github site 中描述的教程然后安装了 OpenMesh 8.0,之后,我链接了工具链

-DCMAKE_TOOLCHAIN_FILE=/home/diolante/vcpkg/scripts/buildsystems/vcpkg.cmake 

在 Clion 工具链设置中以及当我重新加载 CMakeLists.txt 时我在 Clion 项目中改变的:
# CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(lul)

find_package(openmesh REQUIRED)

add_executable(main main.cpp)
target_link_libraries(main openmesh)

Clion 输出返回以下错误:
CMake Error at /home/diolante/vcpkg/scripts/buildsystems/vcpkg.cmake:288 (_find_package):   By not providing "Findopenmesh.cmake" in CMAKE_MODULE_PATH this project has   asked CMake to find a package configuration file provided by "openmesh",   but CMake did not find one.

  Could not find a package configuration file provided by "openmesh" with any
  of the following names:

    openmeshConfig.cmake
    openmesh-config.cmake

  Add the installation prefix of "openmesh" to CMAKE_PREFIX_PATH or set
  "openmesh_DIR" to a directory containing one of the above files. If
  "openmesh" provides a separate development package or SDK, be sure it has
  been installed.

最佳答案

以下内容基于 Visual Studio 编译器,但应该很容易适用于不同的环境。
首先,您需要安装要使用的三元组,例如

vcpkg install openmesh --triplet x64-windows --triplet x86-windows
(如果您不确定是构建项目 x64 还是 x86,只需安装这两个三元组。)
在“构建、执行、部署”下的“工具链”条目中选择合适的工具链。要使工具链成为默认值,请使用向上和向下的小箭头将其移动到列表中的第一个条目。
Toolchain Selection
在“构建、执行、部署”下的“CMake”条目中选择工具链
ToolchainSelection2
如果您选择了一个未安装 OpenMesh 三元组的工具链/架构,您将准确地看到您遇到的错误。vcpkgOpenMesh 提供两个变量8.1 需要用于指定包含目录和要链接的库,如下所示:
target_include_directories(main PRIVATE ${OPENMESH_INCLUDE_DIRS})
target_link_libraries(main PRIVATE ${OPENMESH_LIBRARIES})
整个CMakeLists.txt对于这个项目,现在看起来像这样:
cmake_minimum_required(VERSION 3.14)
project(lul)

find_package(openmesh REQUIRED)

add_executable(main main.cpp)
target_include_directories(main PRIVATE ${OPENMESH_INCLUDE_DIRS})
target_link_libraries(main PRIVATE ${OPENMESH_LIBRARIES})
# the following line is only needed for Visual Studio compilers
target_compile_definitions(main PRIVATE -D_USE_MATH_DEFINES)
示例项目可以从here下载

关于cmake - 无法在 CLion 中使用与 VCPKG 一起安装的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60684120/

相关文章:

c++ - 如何将CLion C++项目导入Visual Studio?

c++ - CLion 编译器设置

c++ - 点云库不适用于Visual Studio 2019

c++ - Vcpkg 无法在带有 mingw 的 Windows 上运行

c++ - kdevelop : editing CMakeLists. txt

build - 如何从 cmake 中的列表中删除标记?

c - fflush(stdout) 问题;

c++ - vcpkg cmake 找不到 botan

c++ - Qt Creator 如何用作通用 C++ IDE(不使用 Qt 库)?

c++ - 字符串正则表达式替换需要 6 个参数但是..MinGW,CMake,w7