OpenCV Build Error - calib3d

I am currently trying to build my first OpenCV on my Raspberry Pi Zero and I keep getting to this point in the ‘make’ and this error occurs. Please help.

This is my build:
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D ENABLE_NEON=ON
-D ENABLE_VFPV3=ON
-D BUILD_TESTS=OFF
-D INSTALL_PYTHON_EXAMPLES=OFF
-D OPENCV_ENABLE_NONFREE=ON …

[ 67%] Linking CXX shared library …/…/lib/libopencv_calib3d.so

/usr/bin/ld: CMakeFiles/opencv_calib3d.dir/src/usac/ransac_solvers.cpp.o: in function cv::usac::Ransac::run(cv::Ptr<cv::usac::RansacOutput>&)::{lambda(cv::Range const&)#3}::operator()(cv::Range const&) const::{lambda(cv::usac::Score const&, cv::Mat const&, bool)#1}::operator()(cv::usac::Score const, cv::Mat const, bool) const': ransac_solvers.cpp:(.text._ZZZN2cv4usac6Ransac3runERNS_3PtrINS0_12RansacOutputEEEENKUlRKNS_5RangeEE1_clES8_ENKUlRKNS0_5ScoreERKNS_3MatEbE_clESC_SF_b[_ZZZN2cv4usac6Ransac3runERNS_3PtrINS0_12RansacOutputEEEENKUlRKNS_5RangeEE1_clES8_ENKUlRKNS0_5ScoreERKNS_3MatEbE_clESC_SF_b]+0x44): undefined reference to __atomic_load_8’
/usr/bin/ld: ransac_solvers.cpp:(.text._ZZZN2cv4usac6Ransac3runERNS_3PtrINS0_12RansacOutputEEEENKUlRKNS_5RangeEE1_clES8_ENKUlRKNS0_5ScoreERKNS_3MatEbE_clESC_SF_b[_ZZZN2cv4usac6Ransac3runERNS_3PtrINS0_12RansacOutputEEEENKUlRKNS_5RangeEE1_clES8_ENKUlRKNS0_5ScoreERKNS_3MatEbE_clESC_SF_b]+0x74): undefined reference to __atomic_load_8' /usr/bin/ld: ransac_solvers.cpp:(.text._ZZZN2cv4usac6Ransac3runERNS_3PtrINS0_12RansacOutputEEEENKUlRKNS_5RangeEE1_clES8_ENKUlRKNS0_5ScoreERKNS_3MatEbE_clESC_SF_b[_ZZZN2cv4usac6Ransac3runERNS_3PtrINS0_12RansacOutputEEEENKUlRKNS_5RangeEE1_clES8_ENKUlRKNS0_5ScoreERKNS_3MatEbE_clESC_SF_b]+0x400): undefined reference to __atomic_store_8’
/usr/bin/ld: ransac_solvers.cpp:(.text._ZZZN2cv4usac6Ransac3runERNS_3PtrINS0_12RansacOutputEEEENKUlRKNS_5RangeEE1_clES8_ENKUlRKNS0_5ScoreERKNS_3MatEbE_clESC_SF_b[_ZZZN2cv4usac6Ransac3runERNS_3PtrINS0_12RansacOutputEEEENKUlRKNS_5RangeEE1_clES8_ENKUlRKNS0_5ScoreERKNS_3MatEbE_clESC_SF_b]+0x420): undefined reference to __atomic_load_8' /usr/bin/ld: CMakeFiles/opencv_calib3d.dir/src/usac/ransac_solvers.cpp.o: in function cv::usac::Ransac::run(cv::Ptrcv::usac::RansacOutput&)::{lambda(cv::Range const&)#3}::operator()(cv::Range const&) const [clone .isra.0]‘:
ransac_solvers.cpp:(.text.ZZN2cv4usac6Ransac3runERNS_3PtrINS0_12RansacOutputEEEENKUlRKNS_5RangeEE1_clES8.isra.0[ZNSt17_Function_handlerIFvRKN2cv5RangeEEZNS0_4usac6Ransac3runERNS0_3PtrINS5_12RansacOutputEEEEUlS3_E1_E9_M_invokeERKSt9_Any_dataS3]+0xfac): undefined reference to `__atomic_load_8’
collect2: error: ld returned 1 exit status

make[2]: *** [modules/calib3d/CMakeFiles/opencv_calib3d.dir/build.make:788: lib/libopencv_calib3d.so.4.8.0] Error 1

make[1]: *** [CMakeFiles/Makefile2:2450: modules/calib3d/CMakeFiles/opencv_calib3d.dir/all] Error 2
make: *** [Makefile:182: all] Error 2

hmm,

1 Like

I have the same issue. The solution cited is from August 2019, and it’s changes are already present in my versions of CMakeLists.txt, etc. Are there any more recent solutions to this issue, which has resurfaced?

As a stopgap measure to get opencv to compile while this issue gets sorted, you can help the build find the missing library by editing CMakeLists.txt
atomic_load_8 is defined in libatomic.so
Find this file by typing $ sudo find / -type f -name ‘atom.so*’

One of the results is
/usr/lib/arm-linux-gnueabihf/libatomic.so.1.2.0
Now go to your opencv clone folder and edit CMakeLists.txt
pi@raspberrypi:~/opencv $ sudo nano CMakeLists.txt
at line 84 right after

Configure OpenCV CMake hooks

add these 2 lines:
find_library(RESULT libatomic.so.1.2.0 PATHS /usr/lib/arm-linux-gnueabihf)
link_libraries(${RESULT})
Exit and save changes.
Now run cmake with -D OPENCV_FORCE_LIBATOMIC_COMPILER_CHECK=1
as one of your options.
And continue with make to build, which should now go to 100%.