I installed gmp library (version 5.1.2) from source using mingw and msys.
This sample program, taken from Wikipedia:
#include <iostream>
#include <gmp.h>
#include <gmpxx.h>
int main()
{
mpz_class x("7612058254738945");
mpz_class y("9263591128439081");
std::cout << "\n " << x << "\n*\n " << y;
std::cout << "\n--------------------\n" << x * y << "\n\n";
return 0;
}
If I compile with mingw:
g++ -Wall -pedantic -O3 -I/c/Libs/GMP/include -L/c/Libs/GMP/lib hello_gmp.cpp -o hellocpp_gmp -lgmpxx -lgmp
it compiles and runs.
If I compile with visual studio 2010/2012 gives me the following error:
error LNK2001: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,struct __mpz_struct const *)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@PBU__mpz_struct@@@Z)
If I modify the code like this:
#include <iostream>
#include <gmp.h>
#include <gmpxx.h>
int main()
{
mpz_class x("7612058254738945");
mpz_class y("9263591128439081");
mpz_class z("0");
//std::cout << "\n " << x << "\n*\n " << y;
//std::cout << "\n--------------------\n" << x * y << "\n\n";
z = x * y;
std::cout << "\n " << x.get_str() << "\n*\n " << y.get_str();
std::cout << "\n--------------------\n" << z.get_str() << "\n\n";
return 0;
}
it compiles and runs.
In the file "gmpxx.h" the << operator is defined as follows:
line 2054 about:
/ **************** I / O operators **************** /
// These Should (and will) be provided separately
template <class T, class U>
inline std :: ostream & operator <<
(std :: ostream & o, const __ gmp_expr U> & T, expr)
{
__gmp_expr <T, T> const & temp (expr);
return o << temp.__get_mp();
}
template <class T>
inline std :: istream & operator >> (std :: istream & i, __ gmp_expr <t & T, expr)
{
return i >> expr.__get_mp ();
}
line 2880 about:
#define __GMP_DEFINE_BINARY_FUNCTION_UI(fun, eval_fun) \
\
template <class T, class U> \
inline __gmp_expr \
<T, __gmp_binary_expr<__gmp_expr<T, U>, mp_bitcnt_t, eval_fun> > \
fun(const __gmp_expr<T, U> &expr, mp_bitcnt_t l) \
{ \
return __gmp_expr<T, __gmp_binary_expr \
<__gmp_expr<T, U>, mp_bitcnt_t, eval_fun> >(expr, l); \
}
line 3080 about:
__GMP_DEFINE_BINARY_FUNCTION_UI(operator<<, __gmp_binary_lshift)
Thank you very much.