I'm doing a project for school in which I am doing all kinds of different calculations involving prime numbers. These numbers tend to go quite big, hence I went looking for an arbitrary precision library. I decided to go for GMP since I had used it earlier in Game Maker (a relatively unknown program) since someone had made a dll for it.
Now, I have followed the install manual and went ahead to compile GMP. I had great difficulty in doing this as I am totally unfamiliar with UNIX and cygwin. Now that I have tried to include gmpxx.h in Netbeans for a test program, things are going wrong. My code is as follows:
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <gmpxx.h>
#include <stdarg.h>
using namespace std;
int main()
{
mpz_t a;
mpz_init(a);
//cout << mpz_probab_prime_p(a,20);
mpz_clear(a);
}
For both mpz_init and mpz_clear I am getting the same error:
relocation truncated to fit: R_X86_64_PC32 against undefined symbol '__gmpz_[init/clear]'
I am just guessing, but the problem could be any of the following:
It could very well be the latter, although I have experimented with adding directories for the header files and such. How would I fix this error?
Thanks in advance!
Edit: Since this is my first post, could you point out what I need to clarify in order to make this question answerable?
Edit2: This is the compiling log in Netbeans:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/firsttestgmp.exe
make[2]: Entering directory '/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP'
mkdir -p dist/Debug/Cygwin_4.x-Windows
g++ -Lpath/to/gmp/lib -lgmpxx -lgmp -o dist/Debug/Cygwin_4.x-Windows/firsttestgmp build/Debug/Cygwin_4.x-Windows/main.o
build/Debug/Cygwin_4.x-Windows/main.o: In function `main':
/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP/main.cpp:22: undefined reference to `__gmpz_init'
/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP/main.cpp:22:(.text+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__gmpz_init'
/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP/main.cpp:24: undefined reference to `__gmpz_clear'
/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP/main.cpp:24:(.text+0x21): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__gmpz_clear'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/Cygwin_4.x-Windows/firsttestgmp.exe' failed
make[2]: *** [dist/Debug/Cygwin_4.x-Windows/firsttestgmp.exe] Error 1
make[2]: Leaving directory '/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
Edit3: As @rubenvd pointed out, the real error is this:
build/Debug/Cygwin_4.x-Windows/main.o: In function `main':
/cygdrive/e/Documents/NetBeansProjects/FirstTestGMP/main.cpp:22: undefined reference to `__gmpz_init'
Thanks everyone! I fixed my problem by going to: Properties > Build > Linker > Libraries > Add Library Then adding gmp.a and gmpxx.a, which I found in the gmp directory that I compiled.