
Hi, I searched the boost mailing list archives on MPFR and the last query was in Feb 2010 so I think this may be worth a new thread. I'm interested in using MPFR (C library for multiple-precision floating-point computations with *correct rounding - *http://www.mpfr.org/) with some of the boost math libraries (vectors, matrices). Support is available to do this via the bindings in boost/math/bindings/mpfr.hpp<http://www.boost.org/doc/libs/1_45_0/boost/math/bindings/mpfr.hpp>. As per the documentation ( http://www.boost.org/doc/libs/1_45_0/libs/math/doc/sf_and_dist/html/math_too... ): "In order to use these bindings you will need to have installed MPFR plus it's dependency the GMP library and the C++ wrapper for MPFR known as gmpfrxx (or mpfr_class)." However, when compiling the example listed in the documentation: #include <boost/math/bindings/mpfr.hpp> #include <boost/math/special_functions/gamma.hpp> int main() { mpfr_class::set_dprec(500); // 500 bit precision // // Note that the argument to tgamma is an expression template, // that's just fine here: // mpfr_class v = boost::math::tgamma(sqrt(mpfr_class(2))); std::cout << std::setprecision(50) << v << std::endl; } I get a large number of compile errors (attached). I do have GMP, MPFR and gmpfrxx installed, although to get the gmpfrxx example to work (source: example.cpp) I had to comment out the reference to GMP_RND_MAX as this enumerated type value, present in MPFR version 2.4.2, has been removed from mpfr.h from version 3.0.0. Does anyone have any experience is getting boost 1.45.0 running with MPFR 3.0.0? I'm wondering whether this an MPFR problem, a boost bindings problem, or both. cheers, Novak.

On Tue, Feb 1, 2011 at 04:25, Novak Elliott <n.s.j.elliott@curtin.edu.au>wrote:
Hi,
I searched the boost mailing list archives on MPFR and the last query was in Feb 2010 so I think this may be worth a new thread.
I'm interested in using MPFR (C library for multiple-precision floating-point computations with *correct rounding - *http://www.mpfr.org/) with some of the boost math libraries (vectors, matrices). Support is available to do this via the bindings in boost/math/bindings/mpfr.hpp<http://www.boost.org/doc/libs/1_45_0/boost/math/bindings/mpfr.hpp>. As per the documentation ( http://www.boost.org/doc/libs/1_45_0/libs/math/doc/sf_and_dist/html/math_too... ):
"In order to use these bindings you will need to have installed MPFR plus it's dependency the GMP library and the C++ wrapper for MPFR known as gmpfrxx (or mpfr_class)."
However, when compiling the example listed in the documentation:
#include <boost/math/bindings/mpfr.hpp>
#include <boost/math/special_functions/gamma.hpp>
int main() { mpfr_class::set_dprec(500); // 500 bit precision
//
// Note that the argument to tgamma is an expression template, // that's just fine here: //
mpfr_class v = boost::math::tgamma(sqrt(mpfr_class(2)));
std::cout << std::setprecision(50) << v << std::endl;
}
I get a large number of compile errors (attached).
I do have GMP, MPFR and gmpfrxx installed, although to get the gmpfrxx example to work (source: example.cpp) I had to comment out the reference to GMP_RND_MAX as this enumerated type value, present in MPFR version 2.4.2, has been removed from mpfr.h from version 3.0.0.
Does anyone have any experience is getting boost 1.45.0 running with MPFR 3.0.0? I'm wondering whether this an MPFR problem, a boost bindings problem, or both.
cheers, Novak.
It looks like you're not linking your program with mpfr library Surya

Yes, you're right. The object file is compiled ok: g++ -I/path/to/boost_1_45_0 -lgmpfrxx -lmpfr -lgmpxx -lgmp -c boost_mpfr_example.cpp but linking fails in building the executable: g++ -I/path/to/boost_1_45_0 -lgmpfrxx -lmpfr -lgmpxx -lgmp boost_mpfr_example.o -o boost_mpfr_example Actually, simply including <boost/math/bindings/mpfr.hpp> gives the following three errors (i.e. commented out the contents of main): boost_mpfr_example.o: In function `MpFrC::get_base()': boost_mpfr_example.cpp:(.text._ZN5MpFrC8get_baseEv[MpFrC::get_base()]+0x6): undefined reference to `MpFrC::base' boost_mpfr_example.o: In function `MpFrC::get_rnd()': boost_mpfr_example.cpp:(.text._ZN5MpFrC7get_rndEv[MpFrC::get_rnd()]+0x6): undefined reference to `MpFrC::rnd' boost_mpfr_example.o: In function `std::basic_istream<char, std::char_traits<char> >& operator>><__mpfr_struct [1]>(std::basic_istream<char, std::char_traits<char> >&, __gmp_expr<__mpfr_struct [1], __mpfr_struct [1]>&)': boost_mpfr_example.cpp:(.text._ZrsIA1_13__mpfr_structERSiS2_R10__gmp_exprIT_S4_E[std::basic_istream<char, std::char_traits<char> >& operator>><__mpfr_struct [1]>(std::basic_istream<char, std::char_traits<char> >&, __gmp_expr<__mpfr_struct [1], __mpfr_struct [1]>&)]+0x2a): undefined reference to `operator>>(std::basic_istream<char, std::char_traits<char> >&, __mpfr_struct*)' collect2: ld returned 1 exit status I have MPFR 3.0.0-2 (ubuntu packages: libmpfr-dev, libmpfr4), gmp 4.3.2 (libgmp3-dev, libgmp3c2, libgmpxx4ldbl), and gmpfrxx ( http://math.berkeley.edu/~wilken/code/gmpfrxx/). I note that gmpfrxx was "Last updated 2008/11/16 to incorporate new features of MPFR 2.3.*" Has anyone got MPFR 3.0.0 working with boost 1.45.0 and if so, what was your setup? cheers, Novak. On 1 February 2011 09:38, John Maddock <boost.regex@virgin.net> wrote:
I get a large number of compile errors (attached).
Those are all linker errors not compiler errors - are you linking to the correct libraries?
HTH, John. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Yes, you're right. The object file is compiled ok:
g++ -I/path/to/boost_1_45_0 -lgmpfrxx -lmpfr -lgmpxx -lgmp -c boost_mpfr_example.cpp
but linking fails in building the executable:
g++ -I/path/to/boost_1_45_0 -lgmpfrxx -lmpfr -lgmpxx -lgmp boost_mpfr_example.o -o boost_mpfr_example
This is a GCC issue - the libraries being linked to must appear *after* the source files that need them. John.

Oops, a bit of a rookie error. Thanks John. So to summarise for those that search the archives: As per "Link Your Program to a Boost program" ( http://www.boost.org/doc/libs/1_45_0/more/getting_started/unix-variants.html...), and other basic gcc/g++ documentation, the example "Using with MPR / GMP - a High-Precision Floating-Point Library" ( http://www.boost.org/doc/libs/1_45_0/libs/math/doc/sf_and_dist/html/math_too... ): boost_mpfr_example.cpp: #include <boost/math/bindings/mpfr.hpp> #include <boost/math/special_functions/gamma.hpp> int main() { mpfr_class::set_dprec(500); // 500 bit precision // // Note that the argument to tgamma is an expression template, // that's just fine here: // mpfr_class v = boost::math::tgamma(sqrt(mpfr_class(2))); std::cout << std::setprecision(50) << v << std::endl; } Should be compiled and linked with the following command: g++ -I/path/to/boost_1_45_0 boost_mpfr_example.cpp -o boost_mpfr_example -lgmpfrxx -lmpfr -lgmpxx -lgmp On Ubuntu 10.10 the following packages (or source) are needed: - MPFR 3.0.0-2 (ubuntu packages: libmpfr-dev, libmpfr4), - gmp 4.3.2 (libgmp3-dev, libgmp3c2, libgmpxx4ldbl), - gmpfrxx (http://math.berkeley.edu/~wilken/code/gmpfrxx/). Running ./boost_mpfr_example should give: 8.8658142871925912508091761239199431116828551763805e-1 cheers, Novak.
participants (3)
-
John Maddock
-
Novak Elliott
-
Surya Kiran Gullapalli