I have followed this answer and used Boost.Multiprecision to use high accuracy floating point numbers (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;
}
However, I have a serious problem for compilation of this code as I receive the following error:
/usr/include/boost/multiprecision/mpfr.hpp:15:18:
fatal error: mpfr.h: No such file or directory
Even installing libgmp3-dev and gmplib did not work.
What is wrong?
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})
If you want to use the MPFR backend you've got to install it separately, make sure it is built, and make sure its headers are in your compiler's INCLUDE path and its binaries (libraries) are in your linker's command line.
(MPFR is not GMP.)