Ubuntu 14.04 Install opencv3.0, meet relocation error - opencv

Here is my make log:
[ 3%] Built target libwebp
[ 3%] Built target opencv_cudev
[ 7%] Built target opencv_ts_pch_dephelp
[ 7%] Built target pch_Generate_opencv_ts
[ 7%] Built target opencv_core_pch_dephelp
[ 7%] Built target pch_Generate_opencv_core
[ 11%] Built target opencv_core
[ 11%] Built target opencv_imgproc_pch_dephelp
[ 11%] Built target pch_Generate_opencv_imgproc
[ 15%] Built target opencv_imgproc
[ 15%] Built target opencv_imgcodecs_pch_dephelp
[ 15%] Built target pch_Generate_opencv_imgcodecs
[ 15%] Built target opencv_imgcodecs
[ 15%] Built target opencv_videoio_pch_dephelp
[ 15%] Built target pch_Generate_opencv_videoio
Linking CXX shared library ../../lib/libopencv_videoio.so
/usr/bin/ld: /usr/local/lib/libavformat.a(rmsipr.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavformat.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libopencv_videoio.so.3.0.0] Error 1
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make: *** [all] Error 2
I tried to re-build ffmpeg from source, in the beginning, make in ffmpeg meets similiar problem but after I configure using this command:
./configure --prefix=.. --enable-shared --enable-gpl --enable-version3 --enable-runtime-cpudetect --disable-outdev=sdl --disable-opencl --enable-libmp3lame --enable-libx264 --cc="gcc -m64 -fPIC" --extra-cflags="-I../include" --extra-ldflags="-L../lib -ldl"
the ffmpeg is built.
But the opencv make error is still there..
Searched a lot and cannot find a solution.

Remake x264 and ffmpeg basically according to this post:http://www.ozbotz.org/opencv-installation-2-3-1/ (remember to add --enable-shared when configuring x264 and ffmpeg) will solve this problem.

Related

Clang build error: lib/CheckerDependencyHandlingAnalyzerPlugin.so] Error 1

The llvm-project source code is cloned from the newest github repo.
Build command: make -j8.
Clang build error, error message is:
collect2: fatal error: ld terminated with signal 9 [Killed]
compilation terminated.
make[2]: *** [tools/clang/lib/Analysis/plugins/CheckerDependencyHandling/CMakeFiles/CheckerDependencyHandlingAnalyzerPlugin.dir/build.make:146: lib/CheckerDependencyHandlingAnalyzerPlugin.so] Error 1
make[2]: *** Deleting file 'lib/CheckerDependencyHandlingAnalyzerPlugin.so'
make[1]: *** [CMakeFiles/Makefile2:34906: tools/clang/lib/Analysis/plugins/CheckerDependencyHandling/CMakeFiles/CheckerDependencyHandlingAnalyzerPlugin.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 67%] Building CXX object tools/clang/lib/Tooling/CMakeFiles/obj.clangTooling.dir/RefactoringCallbacks.cpp.o
[ 67%] Building CXX object tools/clang/lib/Tooling/CMakeFiles/obj.clangTooling.dir/StandaloneExecution.cpp.o
[ 67%] Building CXX object tools/clang/lib/Tooling/CMakeFiles/obj.clangTooling.dir/NodeIntrospection.cpp.o
[ 67%] Building CXX object lib/Transforms/Scalar/CMakeFiles/LLVMScalarOpts.dir/SpeculativeExecution.cpp.o
[ 67%] Building CXX object tools/clang/lib/Tooling/CMakeFiles/obj.clangTooling.dir/Tooling.cpp.o
[ 67%] Building CXX object lib/Transforms/Scalar/CMakeFiles/LLVMScalarOpts.dir/StraightLineStrengthReduce.cpp.o
[ 67%] Building CXX object lib/Transforms/Scalar/CMakeFiles/LLVMScalarOpts.dir/StructurizeCFG.cpp.o
[ 69%] Building CXX object lib/Transforms/Scalar/CMakeFiles/LLVMScalarOpts.dir/TailRecursionElimination.cpp.o
[ 69%] Building CXX object lib/Transforms/Scalar/CMakeFiles/LLVMScalarOpts.dir/WarnMissedTransforms.cpp.o
[ 69%] Linking CXX static library ../../libLLVMScalarOpts.a
[ 69%] Built target obj.clangTooling
[ 69%] Built target LLVMScalarOpts
[ 69%] Built target SampleAnalyzerPlugin
[ 69%] Built target CheckerOptionHandlingAnalyzerPlugin
make: *** [Makefile:171: all] Error 2
Other informations:
$ cmake --version
cmake version 3.18.2
$ gcc --version
gcc (GCC) 8.3.1 20191121 (Red Hat 8.3.1-5)
$ uname -a
Linux VM-82-98-centos 5.4.32-1-tlinux4-0001 #1 SMP Tue Jul 21 14:24:37 CST 2020 x86_64 x86_64 x86_64 GNU/Linux
Any help will be appreciated!
ld terminated with signal 9 denotes that your computer ran out of memory (RAM) to compile the project.
The first thing you should try is to reduce the number of threads. So instead of make -j8, try make -j4.
If you can't compile even with a single thread, then you will probably need to increase the swap size on your computer.

Issues cross compile opencv 2.4.11 for ARM on x86_64 host

I've been trying to cross compile opencv for an ARM target system. My project is dependent to use opencv 2.4.11.
The target system is a petalinux 2017.2 running on a quad-core Cortex A53 of a Zynq Ultrascale+ FPGA.
My host system is an Ubuntu 16.04 x86_64.
I used the following toolchain.cmake file for configuration:
set( CMAKE_SYSTEM_NAME Linux)
set( CMAKE_SYSTEM_PROCESSOR arm)
set( CMAKE_C_COMPILER /home/benjaminh/petalinux_2017_2/tools/linux-i386/aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc)
set( CMAKE_CXX_COMPILER /home/benjaminh/petalinux_2017_2/tools/linux-i386/aarch64-linux-gnu/bin/aarch64-linux-gnu-g++)
set( CMAKE_FIND_ROOT_PATH /home/benjaminh/embedded_development/ultrazed_repo/scripts/rootfs_part)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
I performed the following steps:
wget https://github.com/Itseez/opencv/archive/2.4.11.zip
unzip 2.4.11.zip
cd opencv-2.4.11
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake ../
make -j4
As you can see, the build process failed with: error: unknown register name 'st' in 'asm'. It seems that it attemps to interpret a x86_64 library with an ARM compiler
[ 44%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/bgfg_gaussmix.cpp.o
[ 44%] Building CXX object modules/photo/CMakeFiles/opencv_photo.dir/src/denoising.cpp.o
In file included from /home/benjaminh/petalinux_2017_2/tools/linux-i386/aarch64-linux-gnu/aarch64-linux-gnu/libc/usr/include/math.h:472:0,
from /home/benjaminh/petalinux_2017_2/tools/linux-i386/aarch64-linux-gnu/aarch64-linux-gnu/include/c++/6.2.1/cmath:45,
from /home/benjaminh/petalinux_2017_2/tools/linux-i386/aarch64-linux-gnu/aarch64-linux-gnu/include/c++/6.2.1/math.h:36,
from /home/benjaminh/embedded_development/opencv-2.4.11/modules/core/include/opencv2/core/types_c.h:94,
from /home/benjaminh/embedded_development/opencv-2.4.11/modules/core/include/opencv2/core/core.hpp:49,
from /home/benjaminh/embedded_development/opencv-2.4.11/modules/highgui/include/opencv2/highgui/highgui.hpp:46,
from /home/benjaminh/embedded_development/opencv-2.4.11/modules/highgui/src/precomp.hpp:47,
from /home/benjaminh/embedded_development/opencv-2.4.11/modules/highgui/src/cap_images.cpp:52:
/usr/include/x86_64-linux-gnu/bits/mathinline.h: In member function ‘virtual bool CvCapture_Images::setProperty(int, double)’:
/usr/include/x86_64-linux-gnu/bits/mathinline.h:889:3: error: unknown register name ‘st’ in ‘asm’
__lrint_code;
^
/usr/include/x86_64-linux-gnu/bits/mathinline.h:889:3: error: unknown register name ‘st’ in ‘asm’
__lrint_code;
^
modules/highgui/CMakeFiles/opencv_highgui.dir/build.make:86: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_images.cpp.o' failed
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_images.cpp.o] Error 1
CMakeFiles/Makefile2:2275: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/all' failed
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 44%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/lkpyramid.cpp.o
[ 44%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/video_init.cpp.o
[ 44%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/bgfg_gmg.cpp.o
[ 44%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/tvl1flow.cpp.o
[ 44%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/bgfg_gaussmix2.cpp.o
[ 44%] Linking CXX shared library ../../lib/libopencv_photo.so
[ 44%] Built target opencv_photo
[ 44%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/kalman.cpp.o
[ 44%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/simpleflow.cpp.o
[ 44%] Linking CXX shared library ../../lib/libopencv_video.so
[ 44%] Built target opencv_video
Makefile:160
: recipe for target 'all' failed
make: *** [all] Error 2
From time to time during the build process warnings like these occure, which indicates that there is something wrong with the set path:
cc1plus: warning: include location "/usr/include/glib-2.0" is unsafe for cross-compilation [-Wpoison-system-directories]
cc1plus: warning: include location "/usr/include/freetype2" is unsafe for cross-compilation [-Wpoison-system-directories]
cc1plus: warning: include location "/usr/include/x86_64-linux-gnu" is unsafe for cross-compilation [-Wpoison-system-directories]
For me it is not clear why it is taking the host path and not the given target root path.
Your toolchain file is incomplete. Does petalinux provide one?
You need to add directives so that make will not attempt to use host includes when building target objects:
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
You may also need to specify the target sys root:
set(CMAKE_SYSROOT /home/devel/petalinux-rootfs)

Opencv install Error while using cmd

I'm going to install opencv with cmake, and when I type mingw32-make in debug folder using cmd, this error appear, someone can help me?
C:\opencv\sources\Built_with_Qt\debug>mingw32-make
[ 2%] Built target zlib
[ 6%] Built target libtiff
[ 10%] Built target libjpeg
[ 15%] Built target libwebp
[ 19%] Built target libjasper
[ 20%] Built target libpng
[ 27%] Built target IlmImf
[ 27%] Built target opencv_hal_pch_dephelp
[ 27%] Built target pch_Generate_opencv_hal
[ 28%] Built target opencv_hal
[ 28%] Built target opencv_core_pch_dephelp
[ 28%] Built target pch_Generate_opencv_core
[ 28%] Linking CXX shared library ..\..\bin\libopencv_core300d.dll
c:/progra~2/dev-cpp/mingw64/bin/../lib/gcc/x86_64-w64- mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find - lRunTmChk
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [bin/libopencv_core300d.dll] Error 1
mingw32-make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
mingw32-make: *** [all] Error 2
From http://answers.opencv.org/question/40159/cannot-compile-opencv-30/:
When using mingw32 you have to disable IPP. This can be done by unchecking WITH_IPP in the CMake-gui or by deleting ippicv from opencv\sources\3rdparty before running CMake. In any case, clean your cache by remove your CMakeCache.txt.

OpenCV compile error Linking CXX shared library ../../lib/libopencv_highgui.so /lib/libbz2.so.1: could not read symbols: File in wrong format

I'm trying to install OpenCV-2.4.9 on my CentOS 6.4. machine.
I downloaded the source in ~/Downloads/opencv-2.4.9.
from there, I did 'mkdir build; cd build'. Then did
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON --enable-shared ..
and did 'make -j2'.
Below is the message I got (this is result of re-running using just 'make')
[ 3%] Built target libtiff
[ 4%] Built target opencv_core_pch_dephelp
[ 4%] Built target pch_Generate_opencv_core
[ 6%] Built target opencv_core
[ 6%] Built target opencv_ts_pch_dephelp
[ 6%] Built target pch_Generate_opencv_ts
[ 6%] Built target opencv_imgproc_pch_dephelp
[ 7%] Built target pch_Generate_opencv_imgproc
[ 11%] Built target opencv_imgproc
[ 11%] Built target opencv_flann_pch_dephelp
[ 11%] Built target pch_Generate_opencv_flann
[ 12%] Built target opencv_flann
[ 12%] Built target opencv_highgui_pch_dephelp
[ 12%] Built target pch_Generate_opencv_highgui
Linking CXX shared library ../../lib/libopencv_highgui.so
/lib/libbz2.so.1: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make[2]: *** [lib/libopencv_highgui.so.2.4.9] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
I did some search, but no good answers. Can anybody give me a hint on what's wrong?
I had the same problem and my solution is remove all build file (or CMakeCache.txt) and cmake again.
The problem is that cmake finds a 32-bit library rather than the 64-bit one, which should be found in /lib64/libbz2.so or /usr/lib64/libbz2.so.
Sometimes the cmake get messed up and keep using the cached variable. So if you remove the cache and cmake again, it should find the correct library.

Error in opencv_video when compiling ROS Hydro from source in Odroid-U3

I'm having a problem when trying to compile ROS Hydro from the source on Odroid-U3. This is the related error:
Built target pch_Generate_opencv_superres
[ 31%] Built target opencv_core
[ 32%] Built target opencv_flann
[ 35%] Built target opencv_ml
[ 42%] Built target opencv_imgproc
[ 42%] Built target opencv_photo
[ 45%] Built target opencv_video
Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/local/lib/libavcodec.a(videodsp_armv5te.o): In function `ff_prefetch_arm':
/home/odroid/odroid-sources/sources/ffmpeg/libavcodec/arm/videodsp_armv5te.S:29:(.text+0x8): relocation truncated to fit: R_ARM_THM_JUMP19 against symbol `ff_prefetch_arm' defined in .text section in /usr/local/lib/libavcodec.a(videodsp_armv5te.o)
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libopencv_highgui.so.2.4.6] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
<== Failed to process package 'opencv2':
Command '/home/odroid/ros_catkin_ws/install_isolated/env.sh make -j4 -l4' returned non-zero exit status 2
Reproduce this error by running:
==> cd /home/odroid/ros_catkin_ws/build_isolated/opencv2 && /home/odroid/ros_catkin_ws/install_isolated/env.sh make -j4 -l4
Command failed, exiting.
Already tried to install those libraries by sudo apt-get install but no difference. Any help would be awesome. Thanks!

Resources