📅 2017-Dec-22 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ error, gcc, linker ⬩ 📚 Archive
Building a large project that involved linking with many libraries, I got this linking error:
Linking CXX shared library ../../lib/libfoobar.so /usr/bin/ld: /somepath/opencv-2.4/lib/libopencv_imgproc.a(clahe.cpp.o): unrecognized relocation (0x2a) in section `.text._ZN12_GLOBAL__N_1L15CLAHE_Impl_infoEv' /usr/bin/ld: final link failed: Bad value
At first I suspected some problem with the symbol that you see the linker complaining about above. But using nm I found that the symbol was present and was defined in the archive library file.
Only after eliminating all other possibilities did I discover that the problem was the compiler version. The archive library file had been compiled using GCC 4.8. The linking was being done on a different computer where the compiler was GCC 5.x. The C++ ABI had changed along with the major version difference between the two compilers and this was causing the problem.
Once I rebuilt OpenCV with GCC 5.x and used its archive library file, the linking proceeded smoothly.