我遵循了this answer并使用Boost.Multiprecision使用高精度浮点数(examples)。

main.cpp

#include <iostream>
#include <boost/multiprecision/mpfr.hpp>  // Defines the Backend type that wraps MPFR

int main(int argc, char** argv)
{
    namespace mp = boost::multiprecision;     // Reduce the typing a bit later...
    typedef mp::number<mp::mpfr_float_backend<300> >  my_float;
    my_float a, b, c; // These variables have 300 decimal digits precision

    return 0;
}

但是,由于收到以下错误,我在编译此代码时遇到了严重问题:
/usr/include/boost/multiprecision/mpfr.hpp:15:18:
              fatal error: mpfr.h: No such file or directory

即使安装libgmp3-devgmplib也无效。

怎么了?

CMakeLists.txt
cmake_minimum_required(VERSION 2.8.9)
project (main)

# Libraries
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.54.0 COMPONENTS filesystem regex system thread date_time wave)

if(NOT Boost_FOUND)
    message( FATAL_ERROR "Boost 1.54.0 not found." )
endif()
include_directories(SYSTEM ${Boost_INCLUDE_DIR})

# Flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfatal-errors -std=c++11")


include_directories(${Boost_INCLUDE_DIRS})

# pre executable commands


add_executable(main
    main.cpp
)


# Link
target_link_libraries(main ${Boost_LIBRARIES})
target_link_libraries(main ${CMAKE_THREAD_LIBS_INIT})

最佳答案

如果要使用MPFR后端,则必须单独安装它,请确保它已构建,并确保其头位于编译器的INCLUDE路径中,并且其二进制文件(库)位于链接器的命令行中。

(MPFR不是GMP。)

关于c++ - C++ boost/multiprecision:致命错误:mpfr.h:没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46019674/

10-09 22:45