In R, Using Ubuntu, Try to Install a Lib Depending on Gmp C Lib, It Won't Find Gmp, But I Have Gmp Installed

Error when trying to install Rmpfr in R related to the header file mpfr.h

You should install libmpfr-dev:

sudo apt-get install libmpfr-dev

(answer from the first, highly upvoted comment by @user3710546)

c++ program using GMP library

Get the actual version here GNU GMP Library. Make sure you configure it to be installed in /usr/lib (pass --prefix=/usr to configure).

Here you have documentation: GNU GMP Manual.

You are not using the lib correctly. I don't know if you can directly access mpx values
with C++ functions but, here you have a working example of what you wanted to achieve:

#include<iostream>
#include<gmp.h>

using namespace std;

int main (int argc, char **argv) {

mpz_t a,b,c;
mpz_inits(a,b,c,NULL);

mpz_set_str(a, "1234", 10);
mpz_set_str(b,"-5678", 10); //Decimal base

mpz_add(c,a,b);

cout<<"\nThe exact result is:";
mpz_out_str(stdout, 10, c); //Stream, numerical base, var
cout<<endl;

mpz_abs(c, c);
cout<<"The absolute value result is:";
mpz_out_str(stdout, 10, c);
cout<<endl;

cin.get();

return 0;
}

Compile with:

g++ -lgmp file.cpp -o file


Related Topics



Leave a reply



Submit