简体   繁体   中英

gmp.h missing when trying to use boost library

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM