GMP Compile Error

R

recurphy

I tried to use GMP on a Unix machine, but received errors. What should I do?

C++ Code:
#include <iostream>
#include <gmp.h>

int
main ()
{
mpz_t z;
mpz_init (z);
cin >> z;
cout << z << endl;
}

Command:
g++ gmp.cpp

Message:
Undefined first referenced
symbol in file
__gmpz_init /var/tmp/ccvV4wON.o
__ls__FR7ostreamPC12__mpz_struct /var/tmp/ccvV4wON.o
__rs__FR7istreamP12__mpz_struct /var/tmp/ccvV4wON.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
 
R

Rolf Magnus

I tried to use GMP on a Unix machine, but received errors. What
should I do?

I have no idea what "GMP" is, but it looks to me as if you forgot to
link your program against the library that provides "GMP".
 
G

Gianni Mariani

I tried to use GMP on a Unix machine, but received errors. What should I do?

C++ Code:
#include <iostream>
#include <gmp.h>

int
main ()
{
mpz_t z;
mpz_init (z);
cin >> z;
cout << z << endl;
}

Command:
g++ gmp.cpp

Message:
Undefined first referenced
symbol in file
__gmpz_init /var/tmp/ccvV4wON.o
__ls__FR7ostreamPC12__mpz_struct /var/tmp/ccvV4wON.o
__rs__FR7istreamP12__mpz_struct /var/tmp/ccvV4wON.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

You probably need to link the gmp library ...

g++ gmp.cpp -l<gmp lib>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top