我可以在 CMake 中链接 MPFR 吗?

问题描述 投票:0回答:1

我对 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 ,但错误仍然相同。我做错了什么?

cmake linker mpfr
1个回答
0
投票

好的,现在我的

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})

而且效果很好:)

© www.soinside.com 2019 - 2024. All rights reserved.