0
votes

the Image for nm -CD /usr/local/lib libfhe.so

a C++ code built into a shared library for HELib is using NTL and GMP static library. But it gets following error:

/usr/bin/ld: /usr/local/lib/libntl.a(FFT.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libntl.a: error adding symbols: Bad value collect2: error: ld returned 1 exit status

It was suggested int the post Click here

to recompile NTL and GMP with "-fPIC " flags. I'am not able to find how I should do that.

Edit:

I'm able to build the shared library now after : recompiling GMP and NTL by: ./configure --enable-shared
for gmp and ./configure SHARED=on

After make Install of HELib. I get error when I run the example codes. The link to the Makefile : click to see makefile

Error:

g++ -g -O2 -std=c++11 -pthread -DFHE_THREADS -DFHE_BOOT_THREADS -DFHE_DCRT_THREADS -o Test_General_x Test_General.cpp -L/usr/local/lib -lntl -lgmp -lm -lfhe /usr/local/lib/libfhe.so: undefined reference to write_raw_int(std::ostream&, long, long)' /usr/local/lib/libfhe.so: undefined reference toread_raw_ZZ(std::istream&, NTL::ZZ&)' /usr/local/lib/libfhe.so: undefined reference to void write_raw_vector<long>(std::ostream&, std::vector<long, std::allocator<long> > const&)' /usr/local/lib/libfhe.so: undefined reference towriteEyeCatcher(std::ostream&, char const*)' /usr/local/lib/libfhe.so: undefined reference to write_raw_xdouble(std::ostream&, NTL::xdouble)' /usr/local/lib/libfhe.so: undefined reference toread_ntl_vec_long(std::istream&, NTL::Vec&)' /usr/local/lib/libfhe.so: undefined reference to void read_raw_vector<long>(std::istream&, std::vector<long, std::allocator<long> >&)' /usr/local/lib/libfhe.so: undefined reference toreadEyeCatcher(std::istream&, char const*)' /usr/local/lib/libfhe.so: undefined reference to read_raw_int(std::istream&, long)' /usr/local/lib/libfhe.so: undefined reference toread_raw_xdouble(std::istream&)' /usr/local/lib/libfhe.so: undefined reference to write_raw_ZZ(std::ostream&, NTL::ZZ const&)' /usr/local/lib/libfhe.so: undefined reference towrite_ntl_vec_long(std::ostream&, NTL::Vec const&, long)' collect2: error: ld returned 1 exit status Makefile:179: recipe for target 'Test_General_x' failed make: *** [Test_General_x] Error 1

1
Why are you linking a dynamic library with a static one? Other than that, please read some doc, even .../configure --help gives the answer...Marc Glisse
Because I'm writing a python wrapper module for the shared library's example code (HELib) and HELib library is dependent on the Libraries GMP and NTL. I tried adding ./configure SHARED=on for NTL and ./configure --enable-shared for GMP but I'am still getting the same error that I got before recompiling it to a shared library.4am
If you are getting the same error, it may be that you have several versions of the lib and it isn't picking the right one. Also, I wonder on what system you are that you need to compile GMP/NTL yourself. Anyway, to answer your question, for GMP, try ./configure --help | grep -i pic.Marc Glisse
Thank you, as you said , "it may be that you have several versions of the lib and it isn't picking the right one." this was the case.4am
Since all your link errors involve istream/ostream and you are using C++11, I suspect an incompatible ABI. Did you compile HElib with the same compiler and options as the example? nm -CD /usr/local/lib/libfhe.so and see what looks closest to those undefined references.Marc Glisse

1 Answers

0
votes

Marc Glisse provided the answer for the first two parts of the question.For the third part "Undefined Reference error" the answer is I'd not compiled and linked a x.cpp containing the functions that caused the undefined reference into my shared library. hence check : nm -CD /usr/local/lib/libfhe.so to see if these functions are listed with a linking address or not. If not then check which code provides this functionality. Link that code to the shared library.