2017-09-03 34 views
1

我跟着this answer和使用Boost.Multiprecision使用高精度浮點數(examples)。C++ boost/multiprecision:致命錯誤:mpfr.h:沒有這樣的文件或目錄

的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}) 
+1

如果你想使用[MPFR(http://www.mpfr.org/)後端你必須單獨安裝它,並確保它是在你的編譯器INCLUDE路徑中。 (MPFR不是GMP。) – davidbak

+0

@davidbak,它編譯。非常感謝。只是有一個鏈接失敗。 'CMakeFiles/main.dir/main.cpp.o:在功能升壓::多倍::後端::詳細:: gmp_float_imp <40u> ::〜gmp_float_imp()': main.cpp中:(text._ZN5boost14multiprecision8backends6detail13gmp_float_impILj40EED2Ev [_ZN5boost14multiprecision8backends6detail13gmp_float_impILj40EED5Ev] + 0x21):undefined reference to __gmpf_clear'' – ar2015

+0

所以現在確保你的_built_ MPFR遵循它們的指示,並且結果庫文件在你的_linker_路徑中(或在鏈接器命令行上)......(我是庫談論的是'.o'或者'.so'。) – davidbak

回答

0

如果你想使用MPFR後端你必須單獨安裝它,確保它的建成,並確保它的頭是在你的編譯器的include路徑和其二進制文件(庫)位於鏈接器的命令行中。

(MPFR不是GMP)

相關問題