2

I am trying to use the boost library with QT on windows. I've successfully build the library and also managed to include it in my project. However, on including gmp (#include "boost/multiprecision/gmp.hpp") and creating an object (boost::multiprecision::mpz_int myint;) I get the following error:

C:\Users\Laurenz\Documents\libraries\boost_1_66_0\include\boost\multiprecision\gmp.hpp:31: error: gmp.h: No such file or directory

And indeed, I haven't been able to find any such file in the boost directory. What did I do wrong?

El3ctroGh0st
  • 61
  • 2
  • 5
  • 1
    You need to install [gmp](https://gmplib.org/). It is not part of the boost library. For details see, e.g., https://stackoverflow.com/q/16049726 – RHertel Feb 02 '18 at 17:54
  • Okay I've just downloaded it... But where exactly do I have to move the gmp.h now? – El3ctroGh0st Feb 02 '18 at 18:50
  • It's not just about putting the gmp.h file in the appropriate place. You have to install the entire gmp library, much like the boost library had to be installed. If this is done properly, the system should find the file, possibly after defining some environment variables. I assume that the instructions on how to install and use gmp for a given OS are not difficult to find; either by searching corresponding questions here on SO or by means of your favorite search engine. – RHertel Feb 02 '18 at 19:07
  • Okay, i got it. And I think I managed to install it successfully because now I don't get this error anymore. However, no I'M getting the message `C:\Users\Laurenz\Documents\libraries\boost_1_66_0\include\boost\multiprecision\gmp.hpp:1041: error: undefined reference to `__gmpz_init'`. I've searched around in the Internet and there are other people who were having the same problem, but none of the proposed solutions seem to work for me. Any idea what could fix it? – El3ctroGh0st Feb 02 '18 at 19:28

1 Answers1

1

Install the dependency and link to it. (See What is an undefined reference/unresolved external symbol error and how do I fix it?)

Alternatively, consider not using GMP, using cpp_int.hpp instead.


Since you already installed the GMP library, here's the last step:

Live On Coliru

#include <boost/multiprecision/gmp.hpp>
#include <iostream>

int main() {
    boost::multiprecision::mpz_int i("1238192389824723487823749827349879872342834792374897923479");

    std::cout << pow(i, 3) << "\n";
}

Note the -lgmp flag at the end of the compile/link command:

g++ -std=c++11 -O2 -Wall -Wextra -pedantic main.cpp -o demo -lgmp

Running it:

./demo
1898298004808110659499396020993351679788129852647955073547637871096272981567489303363372689896302906549189545322451852317205769760555889831589125591739044248515246136031239
sehe
  • 374,641
  • 47
  • 450
  • 633