opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
75.95k stars 55.62k forks source link

Undefined reference to __atomic_xxx #15278

Closed fnoop closed 4 years ago

fnoop commented 4 years ago
System information (version)

OpenCV => 4.1.1 OS => Raspbian Buster (Debian 10)

Detailed description

When compiling OpenCV 4.1.1 on Raspbian, i get various undefined references to __atomic_xxx calls. See #15192. Adding -DOPENCV_EXTRA_EXE_LINKER_FLAGS=-latomic to cmake allows OpenCV to compile and install, but the generated libraries are missing the atomic library reference:

[dev] [mav@maverick-raspberry ~]$ ldd -r /srv/maverick/software/opencv/lib/libopencv_core.so.4.1.1
    linux-vdso.so.1 (0xbec57000)
    /usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so => /usr/lib/arm-linux-gnueabihf/libarmmem-v7l.so (0xb6c77000)
    libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xb6c41000)
    libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6c17000)
    librt.so.1 => /lib/arm-linux-gnueabihf/librt.so.1 (0xb6c00000)
    libtbb.so.2 => /srv/maverick/software/tbb/lib/libtbb.so.2 (0xb6bca000)
    libz.so.1 => /lib/arm-linux-gnueabihf/libz.so.1 (0xb6b9f000)
    libopenblas.so.0 => /srv/maverick/software/openblas/lib/libopenblas.so.0 (0xb6269000)
    libstdc++.so.6 => /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 (0xb6122000)
    libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb60a0000)
    libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb6073000)
    libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb5f25000)
    /lib/ld-linux-armhf.so.3 (0xb6fac000)
    libgfortran.so.5 => /usr/lib/arm-linux-gnueabihf/libgfortran.so.5 (0xb5e4c000)
undefined symbol: __atomic_compare_exchange_8   (/srv/maverick/software/opencv/lib/libopencv_core.so.4.1.1)
undefined symbol: __atomic_fetch_sub_8  (/srv/maverick/software/opencv/lib/libopencv_core.so.4.1.1)
undefined symbol: __atomic_load_8   (/srv/maverick/software/opencv/lib/libopencv_core.so.4.1.1)
undefined symbol: __atomic_store_8  (/srv/maverick/software/opencv/lib/libopencv_core.so.4.1.1)
undefined symbol: __atomic_fetch_add_8  (/srv/maverick/software/opencv/lib/libopencv_core.so.4.1.1)

This means anything compiled against opencv also then has these same undefined errors.

I would expect cmake to detect if atomic library is needed and add it automatically, and it should be linked into the core library, and others where necessary.

MKK-a commented 4 years ago

Hi, I have the same issue. With the same Raspbian version and openCV 4.1.1 I have also used suggestions from #15192. However after I have installed opencv via make install and I want to test the installation I get the following

Python 3.7.3 (default, Apr 3 2019, 05:39:12) [GCC 8.2.0] on linux Type "help", "copyright", "credits" or "license" for more information.

import cv2 Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.7/dist-packages/cv2/init.py", line 89, in bootstrap() File "/usr/local/lib/python3.7/dist-packages/cv2/init.py", line 79, in bootstrap import cv2 ImportError: /usr/local/lib/libopencv_core.so.4.1: undefined symbol: __atomic_compare_exchange_8

Any suggestions how to make the installation run? Thanks

alalek commented 4 years ago

@MKK-a try this workaround:

LD_PRELOAD=<path_to_libatomic.so> python
masgari commented 4 years ago

Thanks @alalek for the workaround, works fine on pi zero w:

pi@piz02:/opt/opencv-4.1.1/bin $ sudo find / -type f -name '*atom*.so*'
/usr/lib/arm-linux-gnueabihf/libatomic.so.1.2.0
pi@piz02:/opt/opencv-4.1.1/bin $ LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1.2.0 python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.__version__)
4.1.1
MKK-a commented 4 years ago

Thanks @alalek for the workaround and @masgari for explaining how to get the right path! Works for me on Raspberry Pi 3B+

fnoop commented 4 years ago

Turns out adding -DCMAKE_CXX_FLAGS=-latomic -DOPENCV_EXTRA_EXE_LINKER_FLAGS=-latomic to cmake fixes this. It correctly links atomic lib into the opencv libs, so no further changes necessary to other code that links into opencv. Still I guess opencv should detect if this is necessary and add -latomic where necessary?

ctcarroll commented 4 years ago

@fnoop would you mind sharing your complete Cmake values? I tried the following:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
 -D CMAKE_INSTALL_PREFIX=/usr/local \
 -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
 -D ENABLE_NEON=ON \
 -D ENABLE_VFPV3=ON \
 -D BUILD_TESTS=OFF \
 -D OPENCV_ENABLE_NONFREE=ON \
 -D INSTALL_PYTHON_EXAMPLES=OFF \
 -D CMAKE_CXX_FLAGS=-latomic \
 -D OPENCV_EXTRA_EXE_LINKER_FLAGS=-latomic \
 -D BUILD_EXAMPLES=OFF ..

... which is pieced together from this tutorial - https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/ plus your suggestions.
I still can't get 4.1.1 to get through the make process on Raspian Buster though. Aborts about 30% through with errors like the following.

[modules/ts/CMakeFiles/pch_Generate_opencv_ts.dir/build.make:66: modules/ts/precomp.hpp.gch/opencv_ts_RELEASE.gch] Error 1 make[1]: *** [CMakeFiles/Makefile2:7992: modules/ts/CMakeFiles/pch_Generate_opencv_ts.dir/all] Error 2

I guess I'm not seeing references to atomic so it could be something else, but if you've been successful I wouldn't mind trying your way. Thanks!

fnoop commented 4 years ago

Hi @ctcarroll Sure, you can see my build manifest here: https://github.com/goodrobots/maverick/blob/master/manifests/maverick-modules/maverick_vision/manifests/opencv.pp#L104

You'll have to follow the logic from the top of the manifest, so for an optimised build on a raspberry (arm7 onwards), you'll want to add -DENABLE_PRECOMPILED_HEADERS=NO, -DENABLE_NEON=ON -DENABLE_VFPV3=ON, and I precompile tbb and then add -DWITH_TBB=ON -DBUILD_TBB=OFF as well. It produces a reliable build on the raspberry.

ctcarroll commented 4 years ago

Thanks @fnoop. Appreciate you sharing. I'm still not having any luck getting through the build. I'm getting the exact same error as this person:
https://answers.opencv.org/question/216034/trying-to-install-opencv-with-cmake-on-raspberry-pi-3/ This is my first time using cmake so I could still be doing something wrong, but it seems unrelated so I think I should enter a separate issue for it. Thanks for your help!

alalek commented 4 years ago

@fnoop Could you check this patch: #15353 ?

lloydroc commented 4 years ago

I still cannot compile on rapsberry pi. I am using the latest commit on opencv. I get the following:

[ 52%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/test_misc.cpp.o [ 52%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/test_operations.cpp.o [ 52%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/test_ptr.cpp.o [ 52%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/test_rand.cpp.o [ 52%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/test_rotatedrect.cpp.o [ 52%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/test_umat.cpp.o [ 52%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/test_utils.cpp.o [ 52%] Linking CXX executable ../../bin/opencv_test_core /usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference toatomic_compare_exchange_8' /usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to `atomic_fetch_sub_8' /usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to __atomic_load_8' /usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to__atomic_store_8' /usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to __atomic_fetch_add_8' collect2: error: ld returned 1 exit status make[2]: *** [modules/core/CMakeFiles/opencv_test_core.dir/build.make:571: bin/opencv_test_core] Error 1 make[1]: *** [CMakeFiles/Makefile2:1540: modules/core/CMakeFiles/opencv_test_core.dir/all] Error 2 make: *** [Makefile:163: all] Error 2 pi@raspberrypi:~/opencv/build $

I see the changes in cmake/checks/atomic_check.cpp and at the end of OpenCVDetectCXXCompiler.cmake but when I look in the link.txt files for example modules/core/CMakeFiles/opencv_test_core.dir/link.txt I don't see the -latomic linker flag. If I put in -latomic after -lpthread` and it will compile.

I'd be happy to try some patches and in fact I'm at the same time trying to modify the cmake files.

alalek commented 4 years ago

Could you dump messages about "atomic" from your CMake output? (perhaps you need clear build directory)

-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB (check file: cmake/checks/atomic_check.cpp)

Could you try this additional fix: https://github.com/alalek/opencv/commit/fix_15278_2 ?

lloydroc commented 4 years ago

Hello @alalek it didn't seem to work and I'm not sure why:

Here is the output:

[ 52%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/test_umat.cpp.o
[ 52%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/test_utils.cpp.o
[ 52%] Linking CXX executable ../../bin/opencv_test_core
/usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to `__atomic_compare_exchange_8'
/usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to `__atomic_fetch_sub_8'
/usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to `__atomic_load_8'
/usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to `__atomic_store_8'
/usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to `__atomic_fetch_add_8'
collect2: error: ld returned 1 exit status
make[2]: *** [modules/core/CMakeFiles/opencv_test_core.dir/build.make:571: bin/opencv_test_core] Error 1
make[1]: *** [CMakeFiles/Makefile2:1540: modules/core/CMakeFiles/opencv_test_core.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

I made a fresh build directory and went in there and ran cmake ..

I see this output:

-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB (check file: cmake/checks/atomic_check.cpp)
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB - Success

Here is what I see from my build directory:

pi@raspberrypi:~/opencv/build $ grep -A 1 -B 1 "atomic" ../modules/core/CMakeLists.txt
if(HAVE_CXX_ATOMICS_WITH_LIB)
  ocv_target_link_libraries(${the_module} LINK_PUBLIC atomic)
endif()

This file is what I was going to base the fix off. If it helps any ...

https://github.com/facebook/wangle/blob/master/wangle/cmake/CheckAtomic.cmake

Not sure, maybe I didn't build it right ...

alalek commented 4 years ago

@lloydroc Thank you for update!

Could you dump output from your system of this command?

$ cc -dM -E -x c /dev/null | grep ATOMIC

Could you attach CMake output? (like bottom part of this)

lloydroc commented 4 years ago

Hello @alalek:

pi@raspberrypi:~ $ cc -dM -E -x c /dev/null | grep ATOMIC
#define __ATOMIC_ACQUIRE 2
#define __GCC_ATOMIC_CHAR_LOCK_FREE 1
#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
#define __SIG_ATOMIC_TYPE__ int
#define __GCC_ATOMIC_BOOL_LOCK_FREE 1
#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
#define __GCC_ATOMIC_INT_LOCK_FREE 2
#define __SIG_ATOMIC_MAX__ 0x7fffffff
#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
#define __GCC_ATOMIC_LONG_LOCK_FREE 2
#define __SIG_ATOMIC_WIDTH__ 32
#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 1
#define __ATOMIC_RELAXED 0
#define __ATOMIC_CONSUME 1
#define __ATOMIC_SEQ_CST 5
#define __GCC_ATOMIC_LLONG_LOCK_FREE 1
#define __GCC_ATOMIC_SHORT_LOCK_FREE 1
#define __ATOMIC_ACQ_REL 4
#define __ATOMIC_RELEASE 3

Here is the output of cmake. Note this has the patch you provided in there.

cm.log

Neuro-AI commented 4 years ago

Hello @alalek & @lloydroc

First off, thanks for your help with this. I am running into the same issue with the latest pull from git (2019-08-31). Also, I have implemented the alalek@fix_152. Below is the from my system dump, which looks the same. I am building a pi4 running buster with gcc V8.3 . I was able to install opencv3.4.7 on the pi but had to use -D CMAKE_CXX_FLAGS=-latomic which led me to the same issue above, needing to LD_PRELOAD=<path_to_libatomic.so> python . The previous online build examples, e.g. pyimagesearch openCV 3.4.7 & openCV 4.1.1 seem to all have been built on stretch and not buster. Not sure how that affects things, just something that I have noticed.

Again, many thanks.

#define __ATOMIC_ACQUIRE 2
#define __GCC_ATOMIC_CHAR_LOCK_FREE 1
#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
#define __SIG_ATOMIC_TYPE__ int
#define __GCC_ATOMIC_BOOL_LOCK_FREE 1
#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
#define __GCC_ATOMIC_INT_LOCK_FREE 2
#define __SIG_ATOMIC_MAX__ 0x7fffffff
#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
#define __GCC_ATOMIC_LONG_LOCK_FREE 2
#define __SIG_ATOMIC_WIDTH__ 32
#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 1
#define __ATOMIC_RELAXED 0
#define __ATOMIC_CONSUME 1
#define __ATOMIC_SEQ_CST 5
#define __GCC_ATOMIC_LLONG_LOCK_FREE 1
#define __GCC_ATOMIC_SHORT_LOCK_FREE 1
#define __ATOMIC_ACQ_REL 4
#define __ATOMIC_RELEASE 3
lloydroc commented 4 years ago

Hello @Neuro-AI good point. I am on a raspberry pi b+ and below are my os version and kernel version. I'm also on buster.

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.19.57-v7+ #1244 SMP Thu Jul 4 18:45:25 BST 2019 armv7l GNU/Linux
pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
pi@raspberrypi:~ $

`

Neuro-AI commented 4 years ago

Hello @lloydroc,

Looks like we are running on similar systems.

cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

$ uname -a
Linux Pi 4.19.66-v7l+ #1253 SMP Thu Aug 15 12:02:08 BST 2019 armv7l GNU/Linux

$ cat /proc/version
Linux version 4.19.66-v7l+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1253 SMP Thu Aug 15 12:02:08 BST 2019

$ gcc --version
gcc (Raspbian 8.3.0-6+rpi1) 8.3.0
Neuro-AI commented 4 years ago

So I tried to force the location of libatomic.so

$ sudo find / -name 'libatomic.so'
/opt/cross-pi-gcc-8.3.0-64/aarch64-linux-gnu/lib64/libatomic.so
/opt/native-pi-gcc-8.3.0-64/lib64/libatomic.so

in OpenCVDetectCXXCompiler.cake

+ln 199: list(APPEND OPENCV_LINKER_LIBS "/opt/cross-pi-gcc-8.3.0-64/aarch64-linux-gnu/lib64/libatomic.so")

and commented everything that followed

#if((HAVE_CXX11
#        AND NOT MSVC
#        AND NOT (X86 OR X86_64)
#    AND NOT OPENCV_SKIP_LIBATOMIC_COMPILER_CHECK)
#    OR OPENCV_FORCE_LIBATOMIC_COMPILER_CHECK
#)
#  ocv_check_compiler_flag(CXX "" HAVE_CXX_ATOMICS_WITHOUT_LIB "${OpenCV_SOURCE_DIR}/cmake/checks/atomic_check.cpp")
#  if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
#    list(APPEND CMAKE_REQUIRED_LIBRARIES atomic)
#    ocv_check_compiler_flag(CXX "" HAVE_CXX_ATOMICS_WITH_LIB "${OpenCV_SOURCE_DIR}/cmake/checks/atomic_check.cpp")
#    if(HAVE_CXX_ATOMICS_WITH_LIB)
#      list(APPEND OPENCV_LINKER_LIBS atomic)
#    else()
#      message(FATAL_ERROR "C++11 compiler must support std::atomic")
#    endif()
#  endif()
#endif()

Unfortunately it kicked out this: /opt/native-pi-gcc-8.3.0-64/lib64/libatomic.so: file not recognized: file format not recognized

So, I repeated trying the cross compiled version, /opt/cross-pi-gcc-8.3.0-64/aarch64-linux-gnu/lib64/libatomic.so for ln 199 in OpenCVDetectCXXCompiler.cake

Still no luck.
/opt/cross-pi-gcc-8.3.0-64/aarch64-linux-gnu/lib64/libatomic.so: file not recognized: file format not recognized

Then I noticed at the top of the printout for the cmake command it kicked out the following:

-- Detected processor: armv7l
-- sizeof(void) = 4 on 64 bit processor. Assume 32-bit compilation mode

I wonder if there is an issue with libatomic.soon pi4 being used in 32-bit compile mode. Also, I imagine we want openCV to compile in 64-bit.

OpenCVDetectCXXCompiler.cake Ln 105-116

# Workaround for 32-bit operating systems on x86_64/aarch64 processor
if(CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT FORCE_X86_64)
  message(STATUS "sizeof(void) = 4 on 64 bit processor. Assume 32-bit compilation mode")
  if (X86_64)
    unset(X86_64)
    set(X86 1)
  endif()
  if (AARCH64)
    unset(AARCH64)
    set(ARM 1)
  endif()
endif()
Neuro-AI commented 4 years ago

I switched Ln 199 of OpenCVDetectCXXCompiler.cake to

list(APPEND OPENCV_LINKER_LIBS "/opt/native-pi-gcc-8.3.0-64/include/c++/8.3.0/bits/atomic_base.h")

and now it seems to be compiling. Fingers crossed.

lloydroc commented 4 years ago

Not sure if it helps you at all but if you edit the proper link.txt and add -latomic after the -lpthread then it will work. Seems we need the right OpenCVDetectCXXCompiler.cake option in there. Can we not add to OpenCVDetectCXXCompiler.cake?

list(APPEND OPENCV_LINKER_LIBS -latomic)
Neuro-AI commented 4 years ago

Hi @lloydroc It is possible to add that flag using ccmake .. and adding it to CMAKE_CXX_FLAGS=-latomic . Unfortunately, this reguires @alalek work around above, i.e., LD_PRELOAD=<path_to_libatomic.so> python. Unfortunately the last header file I pointed, see previous post, it at still failed. Back to the drawing board.

lloydroc commented 4 years ago

@alekcac @Neuro-AI if I edit the file OpenCVDetectCXXCompiler.cake and put in:

list(APPEND OPENCV_LINKER_LIBS -latomic)

It should also be noted that the following works!! We can compile atomic_check.cpp without the -latomic flag.

pi@raspberrypi:~/opencv $ g++ cmake/checks/atomic_check.cpp
pi@raspberrypi:~/opencv $ g++ -latomic cmake/checks/atomic_check.cpp
pi@raspberrypi:~/opencv $

It will build just fine. I see this in the link.txt:

pi@raspberrypi:~/opencv/build3 $ grep "latomic" ./modules/core/CMakeFiles/opencv_core.dir/link.txt
/usr/bin/c++ -fPIC    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG   -Wl,--gc-sections   -shared -Wl,-soname,libopencv_core.so.4.1 -o ../../lib/libopencv_core.so.4.1.1 CMakeFiles/opencv_core.dir/src/algorithm.cpp.o CMakeFiles/opencv_core.dir/src/alloc.cpp.o CMakeFiles/opencv_core.dir/src/arithm.cpp.o CMakeFiles/opencv_core.dir/src/arithm.dispatch.cpp.o CMakeFiles/opencv_core.dir/src/array.cpp.o CMakeFiles/opencv_core.dir/src/async.cpp.o CMakeFiles/opencv_core.dir/src/batch_distance.cpp.o CMakeFiles/opencv_core.dir/src/bindings_utils.cpp.o CMakeFiles/opencv_core.dir/src/channels.cpp.o CMakeFiles/opencv_core.dir/src/check.cpp.o CMakeFiles/opencv_core.dir/src/command_line_parser.cpp.o CMakeFiles/opencv_core.dir/src/conjugate_gradient.cpp.o CMakeFiles/opencv_core.dir/src/convert.dispatch.cpp.o CMakeFiles/opencv_core.dir/src/convert_c.cpp.o CMakeFiles/opencv_core.dir/src/convert_scale.dispatch.cpp.o CMakeFiles/opencv_core.dir/src/copy.cpp.o CMakeFiles/opencv_core.dir/src/count_non_zero.dispatch.cpp.o CMakeFiles/opencv_core.dir/src/cuda_gpu_mat.cpp.o CMakeFiles/opencv_core.dir/src/cuda_host_mem.cpp.o CMakeFiles/opencv_core.dir/src/cuda_info.cpp.o CMakeFiles/opencv_core.dir/src/cuda_stream.cpp.o CMakeFiles/opencv_core.dir/src/datastructs.cpp.o CMakeFiles/opencv_core.dir/src/directx.cpp.o CMakeFiles/opencv_core.dir/src/downhill_simplex.cpp.o CMakeFiles/opencv_core.dir/src/dxt.cpp.o CMakeFiles/opencv_core.dir/src/gl_core_3_1.cpp.o CMakeFiles/opencv_core.dir/src/glob.cpp.o CMakeFiles/opencv_core.dir/src/hal_internal.cpp.o CMakeFiles/opencv_core.dir/src/kmeans.cpp.o CMakeFiles/opencv_core.dir/src/lapack.cpp.o CMakeFiles/opencv_core.dir/src/lda.cpp.o CMakeFiles/opencv_core.dir/src/logger.cpp.o CMakeFiles/opencv_core.dir/src/lpsolver.cpp.o CMakeFiles/opencv_core.dir/src/lut.cpp.o CMakeFiles/opencv_core.dir/src/mathfuncs.cpp.o CMakeFiles/opencv_core.dir/src/mathfuncs_core.dispatch.cpp.o CMakeFiles/opencv_core.dir/src/matmul.dispatch.cpp.o CMakeFiles/opencv_core.dir/src/matrix.cpp.o CMakeFiles/opencv_core.dir/src/matrix_c.cpp.o CMakeFiles/opencv_core.dir/src/matrix_decomp.cpp.o CMakeFiles/opencv_core.dir/src/matrix_expressions.cpp.o CMakeFiles/opencv_core.dir/src/matrix_iterator.cpp.o CMakeFiles/opencv_core.dir/src/matrix_operations.cpp.o CMakeFiles/opencv_core.dir/src/matrix_sparse.cpp.o CMakeFiles/opencv_core.dir/src/matrix_wrap.cpp.o CMakeFiles/opencv_core.dir/src/mean.dispatch.cpp.o CMakeFiles/opencv_core.dir/src/merge.dispatch.cpp.o CMakeFiles/opencv_core.dir/src/minmax.cpp.o CMakeFiles/opencv_core.dir/src/norm.cpp.o CMakeFiles/opencv_core.dir/src/ocl.cpp.o CMakeFiles/opencv_core.dir/src/opencl/runtime/opencl_clamdblas.cpp.o CMakeFiles/opencv_core.dir/src/opencl/runtime/opencl_clamdfft.cpp.o CMakeFiles/opencv_core.dir/src/opencl/runtime/opencl_core.cpp.o CMakeFiles/opencv_core.dir/src/opengl.cpp.o CMakeFiles/opencv_core.dir/src/out.cpp.o CMakeFiles/opencv_core.dir/src/ovx.cpp.o CMakeFiles/opencv_core.dir/src/parallel.cpp.o CMakeFiles/opencv_core.dir/src/parallel_impl.cpp.o CMakeFiles/opencv_core.dir/src/pca.cpp.o CMakeFiles/opencv_core.dir/src/persistence.cpp.o CMakeFiles/opencv_core.dir/src/persistence_json.cpp.o CMakeFiles/opencv_core.dir/src/persistence_types.cpp.o CMakeFiles/opencv_core.dir/src/persistence_xml.cpp.o CMakeFiles/opencv_core.dir/src/persistence_yml.cpp.o CMakeFiles/opencv_core.dir/src/rand.cpp.o CMakeFiles/opencv_core.dir/src/softfloat.cpp.o CMakeFiles/opencv_core.dir/src/split.dispatch.cpp.o CMakeFiles/opencv_core.dir/src/stat.dispatch.cpp.o CMakeFiles/opencv_core.dir/src/stat_c.cpp.o CMakeFiles/opencv_core.dir/src/stl.cpp.o CMakeFiles/opencv_core.dir/src/sum.dispatch.cpp.o CMakeFiles/opencv_core.dir/src/system.cpp.o CMakeFiles/opencv_core.dir/src/tables.cpp.o CMakeFiles/opencv_core.dir/src/trace.cpp.o CMakeFiles/opencv_core.dir/src/types.cpp.o CMakeFiles/opencv_core.dir/src/umatrix.cpp.o CMakeFiles/opencv_core.dir/src/utils/datafile.cpp.o CMakeFiles/opencv_core.dir/src/utils/filesystem.cpp.o CMakeFiles/opencv_core.dir/src/utils/logtagconfigparser.cpp.o CMakeFiles/opencv_core.dir/src/utils/logtagmanager.cpp.o CMakeFiles/opencv_core.dir/src/utils/samples.cpp.o CMakeFiles/opencv_core.dir/src/va_intel.cpp.o CMakeFiles/opencv_core.dir/opencl_kernels_core.cpp.o -Wl,-rpath,:::::::::::::: -latomic -ldl -lm -lpthread -lrt ../../3rdparty/lib/libtegra_hal.a /usr/lib/arm-linux-gnueabihf/libz.so ../../3rdparty/lib/libittnotify.a ../../3rdparty/lib/libtegra_hal.a -ldl
pi@raspberrypi:~/opencv/build3 $

I'm going to try a slight modification to @alalek patch with the if conditions.

Neuro-AI commented 4 years ago

@lloydroc & @alalek That did it. It compiled and unlike 3.4.7 is it also working. Nicely done! Many Many Thanks! Using the pyimagesearch example code image

lloydroc commented 4 years ago

@Neuro-AI that is good to hear that method worked! I actually made a slight change to what @alalek proposed and this seems to work and be a bit more safe - see his checks in the patch. Really all I did was modify what @alalek did but change atomic to -latomic.

cmake/OpenCVDetectCXXCompiler.cmake

pi@raspberrypi:~/opencv $ grep -A 6 -B 6 "ATOMICS" cmake/OpenCVDetectCXXCompiler.cmake
if((HAVE_CXX11
        AND NOT MSVC
        AND NOT (X86 OR X86_64)
    AND NOT OPENCV_SKIP_LIBATOMIC_COMPILER_CHECK)
    OR OPENCV_FORCE_LIBATOMIC_COMPILER_CHECK
)
  ocv_check_compiler_flag(CXX "" HAVE_CXX_ATOMICS_WITHOUT_LIB "${OpenCV_SOURCE_DIR}/cmake/checks/atomic_check.cpp")
  if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
    list(APPEND CMAKE_REQUIRED_LIBRARIES -latomic)
    ocv_check_compiler_flag(CXX "" HAVE_CXX_ATOMICS_WITH_LIB "${OpenCV_SOURCE_DIR}/cmake/checks/atomic_check.cpp")
    if(HAVE_CXX_ATOMICS_WITH_LIB)
      list(APPEND OPENCV_LINKER_LIBS -latomic)
    else()
      message(FATAL_ERROR "C++11 compiler must support std::atomic")
    endif()
  endif()
endif()
pi@raspberrypi:~/opencv $

Apply the above block to the cmake/OpenCVDetectCXXCompiler.cmake. This is the patch that seems to work.

What is a bit strange to me is I don't see -latomic in the link.txt files. It would be nice if someone could confirm this works for them on raspberry pi on buster as well. Also, it fully builds with all the modules but the end of the build ends at 52% saying it's linking ../../bin/opencv_test_core

To apply the fix for this bug on the raspberry pi I'm just doing the following. It's simple and straighforward:

$ git clone <latest opencv>
$ cd opencv
$ # apply the patch above to cmake/OpenCVDetectCXXCompiler.cmake at the bottom of file
$ mkdir build
$ cd build
$ cmake ..
$ make # you will know here if this works or not. WARING it takes about 2.5 hours 
alalek commented 4 years ago

@lloydroc Please try to replace check in cmake/checks/atomic_check.cpp:

-std::atomic<int> x;
+std::atomic<long long> x;

Re-run CMake checks again:

cmake -U*ATOMIC* .

and dump CMake output about "atomic" checks.

lloydroc commented 4 years ago
pi@raspberrypi:~/opencv/build7 $ cat build.log
-- Detected processor: armv7l
-- sizeof(void) = 4 on 64 bit processor. Assume 32-bit compilation mode
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB (check file: cmake/checks/atomic_check.cpp)
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB - Failed
-- Performing Test HAVE_CXX_ATOMICS_WITH_LIB (check file: cmake/checks/atomic_check.cpp)
-- Performing Test HAVE_CXX_ATOMICS_WITH_LIB - Success
-- Looking for ccache - not found
-- Found ZLIB: /usr/lib/arm-linux-gnueabihf/libz.so (found suitable version "1.2.11", minimum required is "1.2.3")
-- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR)
-- libjpeg-turbo: VERSION = 2.0.2, BUILD = opencv-4.1.1-dev-libjpeg-turbo
-- Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR)
-- Could NOT find Jasper (missing: JASPER_LIBRARIES JASPER_INCLUDE_DIR)
-- Found ZLIB: /usr/lib/arm-linux-gnueabihf/libz.so (found version "1.2.11")
-- Checking for module 'gtk+-3.0'
--   No package 'gtk+-3.0' found
-- Checking for module 'gtk+-2.0'
--   No package 'gtk+-2.0' found
-- Checking for module 'gthread-2.0'
--   No package 'gthread-2.0' found
-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- Could NOT find Atlas (missing: Atlas_CBLAS_INCLUDE_DIR Atlas_CLAPACK_INCLUDE_DIR Atlas_CBLAS_LIBRARY Atlas_BLAS_LIBRARY Atlas_LAPACK_LIBRARY)
-- Could NOT find BLAS (missing: BLAS_LIBRARIES)
-- LAPACK requires BLAS
-- A library with LAPACK API not found. Please specify library location.
-- Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
-- OpenCV Python: during development append to PYTHONPATH: /home/pi/opencv/build7/python_loader
-- Checking for modules 'libavcodec;libavformat;libavutil;libswscale'
--   No package 'libavcodec' found
--   No package 'libavformat' found
--   No package 'libavutil' found
--   No package 'libswscale' found
-- Checking for module 'gstreamer-base-1.0'
--   No package 'gstreamer-base-1.0' found
-- Checking for module 'gstreamer-app-1.0'
--   No package 'gstreamer-app-1.0' found
-- Checking for module 'gstreamer-riff-1.0'
--   No package 'gstreamer-riff-1.0' found
-- Checking for module 'gstreamer-pbutils-1.0'
--   No package 'gstreamer-pbutils-1.0' found
-- Checking for module 'libdc1394-2'
--   No package 'libdc1394-2' found
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.sse2.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.sse3.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.ssse3.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.sse4_1.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.sse4_2.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.avx.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.fp16.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.avx512_skx.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin256.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin256.avx512_skx.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin512.avx512_skx.cpp
-- Excluding from source files list: modules/imgproc/src/corner.avx.cpp
-- Excluding from source files list: modules/imgproc/src/imgwarp.avx2.cpp
-- Excluding from source files list: modules/imgproc/src/imgwarp.sse4_1.cpp
-- Excluding from source files list: modules/imgproc/src/resize.avx2.cpp
-- Excluding from source files list: modules/imgproc/src/resize.sse4_1.cpp
-- Excluding from source files list: modules/imgproc/src/sumpixels.avx512_skx.cpp
-- Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': /home/pi/opencv/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
-- opencv_dnn: filter out cuda4dnn source code
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx512_skx.cpp
-- Excluding from source files list: modules/features2d/src/fast.avx2.cpp
--
-- General configuration for OpenCV 4.1.1-dev =====================================
--   Version control:               4.1.1-159-g834c99255-dirty
--
--   Platform:
--     Timestamp:                   2019-09-04T02:35:30Z
--     Host:                        Linux 4.19.57-v7+ armv7l
--     CMake:                       3.13.4
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               Release
--
--   CPU/HW features:
--     Baseline:
--       requested:                 DETECT
--       disabled:                  VFPV3 NEON
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/c++  (ver 8.3.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--gc-sections
--     Linker flags (Debug):        -Wl,--gc-sections
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          -latomic dl m pthread rt
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching ts video videoio
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 java js python2 python3
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
--
--   GUI:
--     GTK+:                        NO
--     VTK support:                 NO
--
--   Media I/O:
--     ZLib:                        /usr/lib/arm-linux-gnueabihf/libz.so (ver 1.2.11)
--     JPEG:                        libjpeg-turbo (ver 2.0.2-62)
--     WEBP:                        build (ver encoder: 0x020e)
--     PNG:                         /usr/lib/arm-linux-gnueabihf/libpng.so (ver 1.6.36)
--     TIFF:                        build (ver 42 - 4.0.10)
--     JPEG 2000:                   build (ver 1.900.1)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      NO
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     GStreamer:                   NO
--     v4l/v4l2:                    YES (linux/videodev2.h)
--
--   Parallel framework:            pthreads
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Lapack:                      NO
--     Eigen:                       NO
--     Custom HAL:                  YES (carotene (ver 0.0.1))
--     Protobuf:                    build (3.5.1)
--
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/pi/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python (for build):            /usr/bin/python2.7
--
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Install to:                    /usr/local
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/opencv/build7
pi@raspberrypi:~/opencv/build7 $
alalek commented 4 years ago

@lloydroc Thank you for update! Looks good. CMake should add atomic lib now into build commands. Could you check that?

lloydroc commented 4 years ago

Hello @alalek yes the "-latomic" flags are in the build commands and it all builds for me.

Here is the edit I have to the OpenCVDetectCXXCompiler.cmake

if((HAVE_CXX11
        AND NOT MSVC
        AND NOT (X86 OR X86_64)
    AND NOT OPENCV_SKIP_LIBATOMIC_COMPILER_CHECK)
    OR OPENCV_FORCE_LIBATOMIC_COMPILER_CHECK
)
  ocv_check_compiler_flag(CXX "" HAVE_CXX_ATOMICS_WITHOUT_LIB "${OpenCV_SOURCE_DIR}/cmake/checks/atomic_check.cpp")
  if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
    list(APPEND CMAKE_REQUIRED_LIBRARIES atomic)
    ocv_check_compiler_flag(CXX "" HAVE_CXX_ATOMICS_WITH_LIB "${OpenCV_SOURCE_DIR}/cmake/checks/atomic_check.cpp")
    if(HAVE_CXX_ATOMICS_WITH_LIB)
      list(APPEND OPENCV_LINKER_LIBS atomic)
    else()
      message(FATAL_ERROR "C++11 compiler must support std::atomic")
    endif()
  endif()
endif()
martin762 commented 4 years ago

Hello, Many thanks to alalec, lloydroc et al for following through on the Raspi Pi compile issues with 4.1.1. I downloaded the 4.1.2-pre last week and successfully compiled on my Raspi Pi 4 with Buster. However I had to add the -DCMAKE_CXX_FLAGS=-latomic to avoid the undefined symbols error as listed at the top of the post. With that addition the compile was 100% successful , latomic seen in the link.txt files, and opencv worked. I noted that the flag HAVE_CXX_ATOMICS_WITHOUT_LIB was set and so my limited logic suggests that OpenCVDetectCXXCompiler.cmake amendments did nothing except initiate the checks. Is there another step/ compile code change to eliminate the CXX_FLAGS= from cmake?

I also tried to compile the official 4.1.1 archive, with and without the 15353 changes, but with DCMAKE_CXX_FLAGS=-latomic added to cmake both times. It compiled 100% both times. The compiled output was the same i.e the latomic was missing from the link.txt files on both occasions. I may have made an error when copying the changes because I expected success with the amended/ new files added. Or are there other relevant changes to 4.1.2-pre? Appreciate any comments or pointers you may have.

One last question. 4.1.2-pre was compiled without the opencv_contrib modules. Are they version dependent? many thanks, Martin

martin762 commented 4 years ago

PS. I have not incorporated 15540. Would it be relevant? M

mshabunin commented 4 years ago

@martin762 , yes it should be relevant. Could you please try it too?

martin762 commented 4 years ago

@msshabunin, thanks for the prompt. It works! I have just taken the latest opencv-master (4.1.2-pre) and added the 15540 patch/delta (raspipi4 buster). I used cmake .., followed by make -j4, and the compile continued to the end without any error. The link.txt checks reveal that latomic has been added. I also noted that the atomic_check.cpp now gives me a HAVE_CXX_ATOMICS_WITH_LIB - Success (HAVE_CXX_ATOMICS_WITHOUT_LIB - Failed). That is a totally different result from before.

In conclusion that has fixed the issue subject to continuing with the install, which I expect to be successful and give me a working opencv without specifying =latomics at the cmake stage.. To be thorough I will repeat the compile with the usual cmake options and revert.

Now the big question - how does that little change,i.e. from defining integer variables of standard to very long length, make the big difference to the atomic flag check?

Martin

martin762 commented 4 years ago

Just to confirm a successful compile and install (import C2 version check ok) when adding the usual CMAKE options on my Raspi Pi4B, Raspian Buster, with the latest 4.1.2-pre and the 15540 correction. Job done. Many thanks.

Happy to do checks/ verification on my Raspi Pi 3B and 4B for future releases of opencv 3 and 4 if that would be helpful.

Would also be interested to know the why's and wherefore's of the above changes necessary due to the pi4 h/w and/or Buster OS. Martin

TamNguyen0691 commented 4 years ago

Thank you very much @alalek for the workaround @masgari for teaching how to get the right path!!! Works for me on Raspberry Pi 4 P/s: I don't known how it work but it also workable :) thank you!!!

DuoBelt commented 4 years ago

Thanks @alalek for the workaround, works fine on pi zero w:

pi@piz02:/opt/opencv-4.1.1/bin $ sudo find / -type f -name '*atom*.so*'
/usr/lib/arm-linux-gnueabihf/libatomic.so.1.2.0
pi@piz02:/opt/opencv-4.1.1/bin $ LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1.2.0 python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.__version__)
4.1.1

..thx :)

` Python 3.7.3 (default, Apr 3 2019, 05:39:12) [GCC 8.2.0] on linux Type "help", "copyright", "credits" or "license" for more information.

import cv2 print(cv2.version) 4.1.1

`

jbeale1 commented 8 months ago

Looks to me like this remains an open issue. Compiling opencv-4.x as of 16-Sep-2023 on RaspberryPi 4 32 bit, following instructions for Ubuntu as shown at https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html

 mkdir -p build && cd build
 cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.x/modules ../opencv-4.x
 cmake --build .

the compile dies at about 54% with below message.
uname reports " 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux"

ransac_solvers.cpp:(.text._ZZN2cv4usac6Ransac3runERNS_3PtrINS0_12RansacOutputEEEENKUlRKNS_5RangeEE1_clES8_.isra.0[_ZNSt17_Function_handlerIFvRKN2cv5RangeEEZNS0_4usac6Ransac3runERNS0_3PtrINS5_12RansacOutputEEEEUlS3_E1_E9_M_invokeERKSt9_Any_dataS3_]+0xfdc): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
gmake[2]: *** [modules/calib3d/CMakeFiles/opencv_calib3d.dir/build.make:787: lib/libopencv_calib3d.so.4.8.0] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:5990: modules/calib3d/CMakeFiles/opencv_calib3d.dir/all] Error 2
gmake: *** [Makefile:182: all] Error 2

EDIT: The compile appears to be working after the workaround of redoing cmake with the additional flag: -DOPENCV_FORCE_LIBATOMIC_COMPILER_CHECK=1 as described in the issue here: https://github.com/opencv/opencv/pull/24031#issuecomment-1645620490

axelpey commented 6 months ago

Can confirm I also have this issue on raspberry pi 4, exact same than @jbeale1 in ransac_solvers.cpp, with the same flags on cmake

EDIT: Workaround also works