0

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

4am
  • 105
  • 1
  • 3
  • 11
  • 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 Jan 11 '19 at 17:03
  • 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 Jan 12 '19 at 05:37
  • 1
    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 Jan 12 '19 at 07:58
  • 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 Jan 12 '19 at 08:00
  • 1
    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 Jan 12 '19 at 08:08
  • yes i compiled HELib also with the same compiler and the same options. Please check the image attached, all undefined references are prefixed by U, sorry but i do not understand why. thank you. – 4am Jan 12 '19 at 10:50
  • what do you mean by incompatible ABI? thank you – 4am Jan 16 '19 at 06:50

2 Answers2

1

For NTL v11.5.1 atleast, doing ./configure --help | grep -i pic (as suggested in one of the comments for GMP) did not help at all - it found no matches. However, making a one line change in the file ntl-11.5.1/src/DoConfig (on line 17) from:

'CXXFLAGS'    => '-g -O2'

to:

'CXXFLAGS'    => '-g -O2 -fPIC',

solved the problem for me.

0

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.

4am
  • 105
  • 1
  • 3
  • 11