Undefined references when installing OpenCV on Raspberry Pi - opencv

I'm trying to install OpenCV on a Raspberry Pi 3 Model B running Buster (July 2019) using this guide. I eventually run into the following error after running the make -j4 command.
/usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to `__atomic_fetch_add_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_store_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_compare_exchange_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:1459:modules/core/CMakeFiles/opencv_test_core.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
My CMake command is:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$cwd/installation/OpenCV-"$cvVersion" \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D OPENCV_PYTHON3_INSTALL_PATH=$cwd/OpenCV-$cvVersion-py3/lib/python3.5/site-packages \
-D WITH_QT=ON \
-D WITH_OPENGL=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
So far, I've run make clean and make to see if a single core installation might help. If it does I will update this post. If it doesn't however, does anyone know how to solve this error?
EDIT: After make clean and make the error still occurred

This problem is also raised here
https://github.com/opencv/opencv/issues/15192
As a workaround try to use cmake option: -DOPENCV_EXTRA_EXE_LINKER_FLAGS=-latomic
You can find an example script here https://gist.github.com/willprice/abe456f5f74aa95d7e0bb81d5a710b60
Edit: I had to call python with
LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1.2.0 python3
in order to import cv2

Related

Cmake not configuring , showing file download HASH MISMATCH error while installing opencv(3.2.0) on ubuntu 18.04

I am installing ros melodic with opencv(3.2.0) on ubuntu 18.04. the ros installation is proper. But im getting stuck in the opencv installation, at the part where you configure cmake.its giving a hash mismatch error
ICV: Downloading ippicv_linux_20151201.tgz...
CMake Error at 3rdparty/ippicv/downloader.cmake:73 (file):
file DOWNLOAD HASH mismatch
for file: [/home/anirudh/opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/ippicv_linux_20151201.tgz]
expected hash: [808b791a6eac9ed78d32a7666804320e]
actual hash: [d41d8cd98f00b204e9800998ecf8427e]
status: [7;"Couldn't connect to server"]
and when i scroll down theres a line that says:
CMake Error at 3rdparty/ippicv/downloader.cmake:77 (message):
ICV: Failed to download ICV package: ippicv_linux_20151201.tgz.
Status=7;"Couldn't connect to server"
This is the command that i ran with the full errors:
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
How to fix it?
I tried running another command:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
> -D CMAKE_INSTALL_PREFIX=/usr/local \
> -D INSTALL_C_EXAMPLES=ON \
> -D INSTALL_PYTHON_EXAMPLES=ON \
> -D OPENCV_GENERATE_PKGCONFIG=ON \
> -D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \
> -D BUILD_EXAMPLES=ON ..
But that too gave the same output with the errors

/usr/bin/ld: cannot find -llib64 when building opencv 4.6 on WSL2

I am trying to compile the opencv 4.6 with Cuda 11.7 and Cudnn 8.4.1 on WSL2 with ubuntu 20.04.
I have configured the cmake successfully by following command:
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_CUDA=ON \
-D WITH_CUDNN=ON \
-D WITH_CUBLAS=ON \
-D WITH_TBB=ON \
-D OPENCV_DNN_CUDA=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D CUDA_ARCH_BIN=7.5 \
-D OPENCV_EXTRA_MODULES_PATH=$HOME/source/opencv_contrib/modules \
-D BUILD_EXAMPLES=OFF \
-D HAVE_opencv_python3=ON \
-D CUDNN_LIBRARY=/usr/local/cuda/lib64 \
-D CUDNN_INCLUDE_DIR=/usr/local/cuda/include \
..
But when I start to build, it comes out the error:
$ make
.
.
.
[ 3%] Linking CXX shared library ../../lib/libopencv_cudev.so
/usr/bin/ld: cannot find -llib64
collect2: error: ld returned 1 exit status
make[2]: *** [modules/cudev/CMakeFiles/opencv_cudev.dir/build.make:86: lib/libopencv_cudev.so.4.6.0] Error 1
make[1]: *** [CMakeFiles/Makefile2:4468: modules/cudev/CMakeFiles/opencv_cudev.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
any ideas?

Error compiling openCV 4.1.2 with CUDA 9.0 in Ubuntu 16.04

Here's my cmake command:
cmake -D CMAKE_BUILD_TYPE=DEBUG\
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D CUDA_ARCH_BIN="6.1" \
-D WITH_TBB=ON \
-D WITH_CUDA=ON \
-D BUILD_opencv_cudacodec=OFF \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D WITH_V4L=ON \
-D WITH_QT=OFF \
-D WITH_OPENGL=ON \
-D WITH_GSTREAMER=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_PC_FILE_NAME=opencv.pc \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_PYTHON3_INSTALL_PATH=~/venv/lib/python3.5/site-packages \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib/modules \
-D PYTHON_EXECUTABLE=~/venv/bin/python \
-D PYTHON_DEFAULT_EXECUTABLE=~/venv/bin/python3.5 \
-D BUILD_EXAMPLES=ON ..
Configuring and generating are successful. However, when I tried to compile it. This error appears:
...
/home/jaylo/opencv/modules/dnn/src/cuda/math.hpp(30): error: no operator "+" matches these operands
operand types are: __half2 + __half2
/home/jaylo/opencv/modules/dnn/src/cuda/math.hpp(54): error: no operator "+" matches these operands
operand types are: __half2 + __half2
/home/jaylo/opencv/modules/dnn/src/cuda/math.hpp(119): error: no operator "+" matches these operands
operand types are: __half2 + __half2
3 errors detected in the compilation of "/tmp/tmpxft_000048a8_00000000-6_activations.cpp1.ii".
CMake Error at cuda_compile_1_generated_activations.cu.o.DEBUG-D.cmake:281 (message):
Error generating file
/home/jaylo/opencv/build/modules/dnn/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_activations.cu.o
modules/dnn/CMakeFiles/opencv_dnn.dir/build.make:434: recipe for target 'modules/dnn/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_activations.cu.o' failed
make[2]: *** [modules/dnn/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_activations.cu.o] Error 1
CMakeFiles/Makefile2:4972: recipe for target 'modules/dnn/CMakeFiles/opencv_dnn.dir/all' failed
make[1]: *** [modules/dnn/CMakeFiles/opencv_dnn.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
What is happening here? It seems that it's a syntax error of the openCV code itself.
CUDA 10.0 added native vector arithmetic operators for the __half2 datatype. The CUDA backend for OpenCV DNN makes use of the aforementioned built-in operators.
You will either have to upgrade to CUDA 10.0 to use the CUDA backend of OpenCV DNN or disable it by unmarking OPENCV_DNN_CUDA in CMake options.
Note: The CUDA backend for OpenCV DNN was merged into master a few weeks ago and is not in any release yet. I suspect you have built the master branch instead of OpenCV 4.1.2.
Turns out that using openCV 4.1.0 solves the problem.

Install OpenCV Ubuntu 16.04 c++11

I try to install OpenCV 3.3.0 on Ubuntu 16.04.
So I write:
cmake -DCMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D ENABLE_CXX11=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.0/modules \
-D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python \
-D BUILD_EXAMPLES=ON ..
But Configuring incomplete, errors occurred!
My CMakeError.log:
Compilation failed:
source file: '/home/natalya/opencv-3.3.0/cmake/checks/cxx11.cpp'
check option: ''
===== BUILD LOG =====
Change Dir: /home/natalya/opencv-3.3.0/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_038ae/fast"
/usr/bin/make -f CMakeFiles/cmTC_038ae.dir/build.make CMakeFiles/cmTC_038ae.dir/build
make[1]: Entering directory '/home/natalya/opencv-3.3.0/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_038ae.dir/cxx11.cpp.o
/usr/bin/c++ -o CMakeFiles/cmTC_038ae.dir/cxx11.cpp.o -c /home/natalya/opencv-3.3.0/cmake/checks/cxx11.cpp
/home/natalya/opencv-3.3.0/cmake/checks/cxx11.cpp:4:2: error: #error "C++11 is not supported"
#error "C++11 is not supported"
^
/home/natalya/opencv-3.3.0/cmake/checks/cxx11.cpp: In function ‘int main()’:
/home/natalya/opencv-3.3.0/cmake/checks/cxx11.cpp:11:10: error: ‘res’ does not name a type
auto res = test();
^
/home/natalya/opencv-3.3.0/cmake/checks/cxx11.cpp:12:12: error: ‘res’ was not declared in this scope
return res;
^
CMakeFiles/cmTC_038ae.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_038ae.dir/cxx11.cpp.o' failed
make[1]: *** [CMakeFiles/cmTC_038ae.dir/cxx11.cpp.o] Error 1
make[1]: Leaving directory '/home/natalya/opencv-3.3.0/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_038ae/fast' failed
make: *** [cmTC_038ae/fast] Error 2
===== END =====
I have read much advice, but no help.
I solve this problem so
cmake -DCMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D ENABLE_CXX11=ON \
-D CMAKE_C_COMPILER=/usr/bin/gcc-5 \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.0/modules \
-D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python \
-D BUILD_EXAMPLES=ON ..
I add this
-D ENABLE_CXX11=ON \
-D CMAKE_C_COMPILER=/usr/bin/gcc-5 \

issues in installing opencv

i wanted to compile the Opencv for the first using the following commands
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules \
-D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python \
-D BUILD_EXAMPLES=ON ..
but i am getting the following error
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:128 (project):
No CMAKE_CXX_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "/home/siddhartha/opencv-3.3.0/build/CMakeFiles/CMakeOutput.log".
See also "/home/siddhartha/opencv-3.3.0/build/CMakeFiles/CMakeError.log".
(cv) siddhartha#wipro:~/opencv-3.3.0/build$
anyone has any idea how to solve this issue .

Resources