在CLion中无法使用通过VCPKG安装的库

12

我按照VCPKG的Github网站中描述的教程操作,安装了OpenMesh 8.0,并连接了工具链。

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

在Clion工具链设置中,当我重新加载在Clion项目中更改的CMakeLists.txt时:

# 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.
1个回答

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

arm-none-eabi-gcc

```
vcpkg install openmesh --triplet x64-windows --triplet x86-windows

如果您不确定要构建项目x64还是x86,请同时安装两个三元组。

在“构建、执行、部署”下的“工具链”中选择正确的工具链。通过使用向上和向下的小箭头将工具链移动到列表中的第一项,使工具链成为默认选项。

工具链选择

在“构建、执行、部署”下的“CMake”条目中选择工具链

ToolchainSelection2

如果您选择了一个没有安装OpenMesh三元组的工具链/体系结构,则会看到您正在遇到的确切错误。

vcpkg提供了两个变量OpenMesh 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)

可以从这里下载示例项目。


你能帮忙将一个可运行的Clion项目示例上传到Github吗?无论使用哪个vcpkg库都可以。 - Just a learner
很遗憾,我没有安装CLion,所以无法帮助你解决这个问题。但我认为原因在于CMakeLists.txt文件中,而不是CLion项目中。 - vre
1
@Justalearner 刚刚安装了CLion并检查了步骤。问题似乎最有可能与缺少OpenMesh vcpkg三元组有关。明天会上传项目。 - vre
感谢您提供的演示项目!@vre - Just a learner
1
修复加一分,对于CLion用户的注意事项:默认情况下,CLion使用Visual Studio作为工具链,但“架构”下拉菜单为空。如果为空,则默认为x86架构,请确保在处理x64项目时明确选择x64! - micka190

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接