How to recompile ntl and gmp libraries with “-fPIC” flag & make HELib as a shared library &...












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 to
read_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 to
writeEyeCatcher(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 to
read_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 to
readEyeCatcher(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 to
read_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 to
write_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











share|improve this question




















  • 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 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 at 5: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 at 7: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 at 8: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 at 8:08
















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 to
read_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 to
writeEyeCatcher(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 to
read_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 to
readEyeCatcher(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 to
read_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 to
write_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











share|improve this question




















  • 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 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 at 5: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 at 7: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 at 8: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 at 8:08














0












0








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 to
read_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 to
writeEyeCatcher(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 to
read_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 to
readEyeCatcher(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 to
read_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 to
write_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











share|improve this question
















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 to
read_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 to
writeEyeCatcher(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 to
read_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 to
readEyeCatcher(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 to
read_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 to
write_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








build compilation shared-libraries gmp ntl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 16 at 6:38







4am

















asked Jan 11 at 14:40









4am4am

35118




35118








  • 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 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 at 5: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 at 7: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 at 8: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 at 8:08














  • 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 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 at 5: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 at 7: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 at 8: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 at 8:08








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
Jan 11 at 17:03





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 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 at 5:37







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 at 5:37






1




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 at 7:58





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 at 7: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 at 8:00





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 at 8:00




1




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 at 8:08





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 at 8:08












1 Answer
1






active

oldest

votes


















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.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54148692%2fhow-to-recompile-ntl-and-gmp-libraries-with-fpic-flag-make-helib-as-a-share%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    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.






    share|improve this answer




























      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.






      share|improve this answer


























        0












        0








        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.






        share|improve this 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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 19 at 11:34









        4am4am

        35118




        35118






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54148692%2fhow-to-recompile-ntl-and-gmp-libraries-with-fpic-flag-make-helib-as-a-share%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Homophylophilia

            Updating UILabel text programmatically using a function

            Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage