我可以在 CMake 中链接 MPFR 吗?

问题描述

我是 cmake 的新手,我在 MacO 上,我正在尝试构建一个 c++ 库,我需要将我的可执行文件链接到 mpfr 以使其工作

这是我的 CMakeLists.txt 文件:

cmake_minimum_required(VERSION 3.19)
project(my_project)

set(CMAKE_CXX_STANDARD 14)
add_executable(my_project main.cpp)

find_package(GSL REQUIRED)
target_link_libraries(my_project GSL::gsl GSL::gslcblas)

find_package(Boost REQUIRED)
target_link_libraries(my_project Boost::boost)

find_package(MPFR REQUIRED) # <- It fails here!
target_link_libraries(my_project MPFR::mpfr)

当我尝试使用 CLion 构建我的项目时,出现以下错误:

CMake Error at CMakeLists.txt:13 (find_package):
  By not providing "FindMPFR.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "MPFR",but
  CMake did not find one.

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

    MPFRConfig.cmake
    mpfr-config.cmake

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

经过一番研究,我发现 Cmake 正确链接了 GSL 和 Boost,因为同时存在 /usr/local/share/cmake/Modules/FindGSL.cmake/usr/local/share/cmake/Modules/FindBoost.cmake 文件,所以我在网上查找了 FindMPFR.cmake 文件以插入到 /usr/local/share/cmake/Modules/ 目录中,我尝试使用 this 一个,但错误仍然相同。我做错了什么?

编辑:

现在我的 CMakeLists.txt 文件看起来像这样:

cmake_minimum_required(VERSION 3.19)
project(my_project)

set(CMAKE_CXX_STANDARD 14)

add_executable(my_project main.cpp )

# Append the cmake/ directory to the CMAKE_MODULE_PATH
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

find_package(GSL REQUIRED)
message(STATUS "GSL Found: ${GSL_FOUND}")
target_link_libraries(my_project GSL::gsl GSL::gslcblas)

find_package(Boost REQUIRED)
message(STATUS "Boost Found: ${Boost_FOUND}")
target_link_libraries(my_project Boost::boost)


find_package(MPFR REQUIRED)
message(STATUS "MPFR Found: ${MPFR_FOUND}")
target_link_libraries(my_project ${MPFR_LIBRARIES})

它工作正常:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...