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'm trying to install the library Normaliz having dependencies like CocoALib, SCIP. I've made its dependencies according to their guidances. However, I get the error while make of Normaliz on both Ubuntu and Mac OSX,
[ 81%] Linking CXX executable normaliz
libnormaliz/libnormaliz.so.3.4.0: undefined reference to `boost::system::system_category()'
libnormaliz/libnormaliz.so.3.4.0: undefined reference to `boost::system::generic_category()'
collect2: error: ld returned 1 exit status
CMakeFiles/normaliz.dir/build.make:99: recipe for target 'normaliz' failed
make[2]: *** [normaliz] Error 1
CMakeFiles/Makefile2:99: recipe for target 'CMakeFiles/normaliz.dir/all' failed
make[1]: *** [CMakeFiles/normaliz.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
I really fed up with it since two weeks! How can it be overcome?
Even if it is boost linkage problem, how can it be linked? There is no option for it. That kinda headaches cause apathy to open-source at least for young programmers like me.
I try to compile a C++ project that uses opencv and cuda (https://github.com/danielsuo/cuSIFT reset to commit 61d8a2e).
To compile the project I use cmake in the following ways:
Method 1
cmake .. && make -j3 demo
This gives me an error message saying
error -- unsupported GNU version! gcc versions later than 5 are not supported!
Method 2
So I set a different compiler for the build like that
CC=/usr/bin/gcc-5 CXX=/usr/bin/g++-5 cmake .. && make -j3 demo
which runs a few steps further but returns an error message during the linking step
[100%] Linking CXX executable demo
/usr/lib/libtbb.so.2: undefined reference to __cxa_init_primary_exception#CXXABI_1.3.11'
/usr/lib/libopencv_objdetect.so.3.2.0: undefined reference to std::thread::_State::~_State()#GLIBCXX_3.4.22'
/usr/lib/libopencv_objdetect.so.3.2.0: undefined reference to std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)())#GLIBCXX_3.4.22'
/usr/lib/libtbb.so.2: undefined reference to std::__exception_ptr::exception_ptr::exception_ptr(void*)#CXXABI_1.3.11'
/usr/lib/libopencv_objdetect.so.3.2.0: undefined reference to typeinfo for std::thread::_State#GLIBCXX_3.4.22'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/demo.dir/build.make:292: demo] Error 1
make[2]: *** [CMakeFiles/Makefile2:105: CMakeFiles/demo.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:112: CMakeFiles/demo.dir/rule] Error 2
make: *** [Makefile:153: demo] Error 2
Method 3
And when I set the compiler like that
cmake .. -DCUDA_HOST_COMPILER=/usr/bin/gcc-5 && make -j3 demo
I also get an error message
[100%] Linking CXX executable demo
/usr/bin/ld: CMakeFiles/demo.dir/demo_generated_cuImage.cu.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: CMakeFiles/demo.dir/demo_generated_cuSIFT.cu.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: CMakeFiles/demo.dir/demo_generated_cuSIFT_H.cu.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: CMakeFiles/demo.dir/extras/demo_generated_matching.cu.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: CMakeFiles/demo.dir/extras/demo_generated_rigidTransform.cu.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: CMakeFiles/demo.dir/extras/demo_generated_homography.cu.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: CMakeFiles/demo.dir/extras/demo_generated_math_utils.cu.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: CMakeFiles/demo.dir/demo_intermediate_link.o: relocation R_X86_64_32S against `__nv_module_id' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/demo.dir/build.make:292: demo] Error 1
make[2]: *** [CMakeFiles/Makefile2:105: CMakeFiles/demo.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:112: CMakeFiles/demo.dir/rule] Error 2
make: *** [Makefile:153: demo] Error 2
Does somebody know how to compile this project?
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?