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

2

There are 2 best solutions below

0
4am On BEST ANSWER

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.

0
Rohit D On

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.