3

我遵循了这个答案并使用Boost.Multiprecision来使用高精度浮点数(示例)。

主文件

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

2 回答 2

1

您必须在 cmake 文件中包含 gmp 和 mfr 的库。

在 qmake 中使用:LIBS += -lgmp -lmpfr

如果你不知道cmake怎么做,就让qmake做一个cmake文件,我没用cmake,但我知道是类似的,但是忘了怎么做,不然我就直接做了,把结果贴出来,sorry,但是这些年来我忘记的所有事情,比如我把我的记忆放在哪里;但和他们一样,这篇文章很旧,所以任何发现它的人都可能会觉得这很有帮助。

这将满足以下内容以及更多内容:

 #include <boost/multiprecision/cpp_dec_float.hpp>
 #include <boost/multiprecision/mpfr.hpp>
 #include <boost/multiprecision/gmp.hpp>
于 2019-03-31T20:17:09.837 回答
1

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

(MPFR 不是 GMP。)

于 2017-09-03T02:30:59.397 回答