mlpack was perfectly compiling on my systems a few days back. I don't know what I did that's causing the following strange linking error:
[ 37%] Linking CXX shared library ../../lib/libmlpack.so
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../lib/libiberty.a(cplus-dem.o): warning: relocation against `libiberty_demanglers' in read-only section `.text'
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../lib/libiberty.a(cp-demangle.o): relocation R_X86_64_PC32 against symbol `cplus_demangle_builtin_types' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [src/mlpack/CMakeFiles/mlpack.dir/build.make:1040: lib/libmlpack.so.3.4] Error 1
make[1]: *** [CMakeFiles/Makefile2:2106: src/mlpack/CMakeFiles/mlpack.dir/all] Error 2
make: *** [Makefile:146: all] Error 2
I tried adding the -fPIC flag to the cmake file but it still gives the same error
I'm writing a C++ program using libtorch and OpenCV.
Here is the output of my CMakeLists.txt, with the libraries versions :
-- Pytorch status :
-- libraries: torch;torch_library;/usr/lib/libc10.so
-- OpenCV library status :
-- version: 3.2.0
-- libraries: opencv_calib3d;opencv_core;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_shape;opencv_stitching;opencv_superres;opencv_video;opencv_videoio;opencv_videostab;opencv_viz;opencv_aruco;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_datasets;opencv_dpm;opencv_face;opencv_freetype;opencv_fuzzy;opencv_hdf;opencv_line_descriptor;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_reg;opencv_rgbd;opencv_saliency;opencv_stereo;opencv_structured_light;opencv_surface_matching;opencv_text;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto
-- include path: /usr/include;/usr/include/opencv
-- Configuring done
-- Generating done
-- Build files have been written to: /home/<my_user>/<project>/cmake-build
You can see that torch needs libc10.so to work.
When I call make, everything goes fine, until this happens during linking :
[ 8%] Linking CXX executable POC_V4
/usr/lib/libc10.so: file not recognized: file format not recognized
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/POC_V4.dir/build.make:298: POC_V4] Error 1
make[1]: *** [CMakeFiles/Makefile2:96: CMakeFiles/POC_V4.dir/all] Error 2
make: *** [Makefile:104: all] Error 2
When I do a file command on this file, I see that it is compiled for x86-64 architectures, instead of ARM.
Here is the output of the file command on /usr/lib/libc10.so and on /usr/lib/libtorch.so.3.0.0 to have a comparison:
/usr/lib/libc10.so: ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=f8019a46a003bc238af0fb3fb8331af8af69aa33, not stripped
/usr/lib/libtorch.so.3.0.0: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=2f8320292f01aab7c9e2e2577b3be2025689c0a7, stripped
How can I have a working libc10.so file ?
EDIT:
I started to re-build PyTorch on my raspberry PI so it would re-build libtorch too.
This takes many hours, and crashed during the night for a linkage problem :
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_fetch_add_8'
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_load_8'
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_exchange_8'
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_fetch_sub_8'
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_compare_exchange_8'
collect2: error: ld returned 1 exit status
make[2]: *** [caffe2/CMakeFiles/conv_to_nnpack_transform_test.dir/build.make:108: bin/conv_to_nnpack_transform_test] Error 1
make[1]: *** [CMakeFiles/Makefile2:2836: caffe2/CMakeFiles/conv_to_nnpack_transform_test.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_fetch_add_8'
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_load_8'
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_exchange_8'
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_fetch_sub_8'
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_compare_exchange_8'
collect2: error: ld returned 1 exit status
make[2]: *** [caffe2/CMakeFiles/depthwise3x3_conv_op_test.dir/build.make:108: bin/depthwise3x3_conv_op_test] Error 1
make[1]: *** [CMakeFiles/Makefile2:2867: caffe2/CMakeFiles/depthwise3x3_conv_op_test.dir/all] Error 2
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_fetch_add_8'
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_load_8'
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_exchange_8'
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_fetch_sub_8'
/usr/bin/ld: /home/<myuser>/pytorch_install/pytorch/build/lib/libcaffe2.so: undefined reference to `__atomic_compare_exchange_8'
collect2: error: ld returned 1 exit status
make[2]: *** [caffe2/CMakeFiles/pattern_net_transform_test.dir/build.make:108: bin/pattern_net_transform_test] Error 1
make[1]: *** [CMakeFiles/Makefile2:2805: caffe2/CMakeFiles/pattern_net_transform_test.dir/all] Error 2
make: *** [Makefile:161: all] Error 2
However, the build outputed a libc10.so file with the following signature!
/usr/lib/libc10.so: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=61d77cfaa9647739e17f6b08caeb53382d9e9108, not stripped
I replaced it in the /usr/lib folder and tried to build my project : It went further than before, and crashed for another file-format problem. This proves that if I manage to fully rebuild libtorch, I should be able to build my project !
Can someone help me solve the new linking problem ?
EDIT #2:
I found this issue with the same problem. Trying the given solution and coming back here if that works to write a full tutorial.
I have found a link overcome the issue you are facing. Please read it through it should solve your solve.
https://github.com/pytorch/pytorch/issues/14727
I finally made it work and detailed it in the answer of this question.
Don't hesitate to improve it if you find errors / bad practices !
I tried to find the same case as mine, but I couldn't. Most of them here are about undefined reference error during compiling their own code, but in my case this error occurred while installing OpenCV.
I referred to this page :
http://milq.github.io/install-opencv-ubuntu-debian/
I use armv7l and debian-scratch 9.3.
I tried to install OpenCV 3.4.0
I have this error :
[ 31%] Building CXX object modules/features2d/CMakeFiles/opencv_features2d.dir/src/akaze.cpp.o
//usr/lib/libgdal.so.20: undefined reference to `XML_SetUserData'
//usr/lib/libgdal.so.20: undefined reference to `XML_SetUnknownEncodingHandler'
//usr/lib/arm-linux-gnueabihf/libharfbuzz.so.0: undefined reference to `FT_Set_Char_Size'
//usr/lib/arm-linux-gnueabihf/libQt5Gui.so.5: undefined reference to `glGenerateMipmap'
//usr/lib/arm-linux-gnueabihf/libQt5Gui.so.5: undefined reference to `glUniform2fv'
//usr/lib/arm-linux-gnueabihf/libbluray.so.1: undefined reference to `FT_GlyphSlot_Embolden'
...
//usr/lib/arm-linux-gnueabihf/libavcodec.so.57: undefined reference to `deflateReset'
/usr/bin/ld: ../../bin/opencv_annotation: hidden symbol `atexit' in /usr/lib/arm-linux-gnueabihf/libc_nonshared.a(atexit.oS) is referenced by DSO
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
apps/annotation/CMakeFiles/opencv_annotation.dir/build.make:100: recipe for target 'bin/opencv_annotation' failed
make[2]: *** [bin/opencv_annotation] Error 1
CMakeFiles/Makefile2:4690: recipe for target 'apps/annotation/CMakeFiles/opencv_annotation.dir/all' failed
make[1]: *** [apps/annotation/CMakeFiles/opencv_annotation.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
I found out it's from a linking library error, but as I'm a beginner of Linux, it couldn't help me.
I hope this question is clear.
I am trying to install OpenCV3 but I keep getting this error:
usr/bin/ld: /usr/local/lib/libpython3.5m.a(abstract.o): relocation R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libpython3.5m.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
modules/python3/CMakeFiles/opencv_python3.dir/build.make:224: recipe for target 'lib/python3/cv2.cpython-35m-x86_64-linux-gnu.so' failed
make[2]: *** [lib/python3/cv2.cpython-35m-x86_64-linux-gnu.so] Error 1
CMakeFiles/Makefile2:7226: recipe for target 'modules/python3/CMakeFiles/opencv_python3.dir/all' failed
make[1]: *** [modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2
Any idea on how to solve it?
I am trying to build zeromq under Windows 7 (x64) with cygwin (x64) and gcc(x86_64)>=4.
configure works but the make step crashes when it reaches curve_keygen.exe
Making all in tools
make[1]: Entering directory '/e/0MQ/zeromq-4.0.3/tools'
CC curve_keygen.o
CCLD curve_keygen.exe
../src/.libs/libzmq.a(libzmq_la-zmq.o):zmq.cpp:(.data+0x0): undefined reference to `__gxx_personality_seh0'
../src/.libs/libzmq.a(libzmq_la-zmq.o):zmq.cpp:(.xdata+0x30): undefined reference to `__gxx_personality_seh0'
../src/.libs/libzmq.a(libzmq_la-zmq.o):zmq.cpp:(.xdata+0x30): relocation truncated to fit: rva32 against undefined symbol `__gxx_personality_seh0'
../src/.libs/libzmq.a(libzmq_la-zmq.o):zmq.cpp:(.xdata+0x1c0): undefined reference to `__gxx_personality_seh0'
../src/.libs/libzmq.a(libzmq_la-zmq.o):zmq.cpp:(.xdata+0x1c0): relocation truncated to fit: rva32 against undefined symbol `__gxx_personality_seh0'
../src/.libs/libzmq.a(libzmq_la-zmq.o):zmq.cpp:(.rdata$.refptr._ZSt7nothrow[.refptr._ZSt7nothrow]+0x0): undefined reference to `std::nothrow'
../src/.libs/libzmq.a(libzmq_la-socket_base.o): In function `zmq::socket_base_t::parse_uri(char const*, std::string&, std::string&)':
.
.
.
collect2: error: ld returned 1 exit status
Makefile:394: recipe for target 'curve_keygen.exe' failed
make[1]: *** [curve_keygen.exe] Error 1
make[1]: Leaving directory '/e/0MQ/zeromq-4.0.3/tools'
Makefile:412: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1
What do I need to do to build zeromq under windows with cygwin.
This indicates that libzmq.la is a C++ library, not a C library. Not sure why that is (it shouldn't) but here is a workaround:
mv tools/curve_keygen.c tools/curve_keygen.cpp
sed -i 's/\.c\>/&pp/' tools/Makefile.am
rm -f tools/.deps/curve_keygen.Po
./autogen.sh
make
This will compile curve_keygen.exe, but does not solve the question of why libzmq.la has C++ dependencies under Cygwin.