CMake Cross compile Arm64 error “unrecognised command line option ‘-msse’” - c++

I am trying to cross-compile openCV for an Arm64 linux platform and am getting the following errors
aarch64-linux-gnu-gcc: error: unrecognised command line option ‘-msse’; did you mean ‘-fdse’?
aarch64-linux-gnu-gcc: error: unrecognised command line option ‘-msse2’
aarch64-linux-gnu-gcc: error: unrecognised command line option ‘-msse3’
I understand that the -msse flags are not compatible with arm64, yet when I generate my makefile from CMake, these flags are include.
My CMake command is
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-DCUDA_NVCC_EXECUTABLE=/usr/local/cuda-10/bin/nvcc \
-DCUDA_HOST_COMPILER=/opt/l4t-gcc-toolchain-64-bit-32-7.1/bin/aarch64-linux-gnu-gcc \
-DCUDA_INCLUDE_DIRS=/usr/local/cuda-10/targets/aarch64-linux/include \
-DCUDA_CUDART_LIBRARY=/usr/local/cuda-10/targets/aarch64-linux/lib/libcudart.so \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=OFF \
-D WITH_CUDA=ON \
-D CUDA_ARCH_BIN="6.2" \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.4.0/modules/ \
-D ENABLE_CXX11=ON ..
I am building on linux ubuntu 18.4.
How to do I tell CMake that the platform is Arm64?
Thanks

I resolved the issue, the missing flag I was looking for was
-D CMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake

Related

Building opencv from source in Mac m1

I'm using the following Make to build OpenCV from source,
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=/Users/Tools/opencv_contrib/modules \
-D PYTHON3_EXECUTABLE=/miniforge/base/envs/envname/bin/python3 \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D WITH_OPENGL=ON \
-DBUILD_ZLIB=OFF \
-D OPENCV_EXTRA_MODULES_PATH=/Users/Tools/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
Unfortunately it doesn't build. It throws the following error,
: error: unknown type name 'AVBSFContext'; did you mean 'AVIOContext'?
I have of course installed FFmpeg. what am I still missing?
I think that you've installed ffmpeg 5 and OpenCV is not yet compatible with it. Please try the following:
brew install ffmpeg#4
brew unlink ffmpeg
brew link ffmpeg#4
and then recompile OpenCV again.

Link error when compiling opencv from source when including ffmpeg compiled from source

I've been stuck on this problem for weeks.
I'm trying to build opencv on a raspberry pi 4 with x264 support. To do this I need to include ffmpeg, and also build that from source.
However when compiling opencv, I'm consistently getting these linker errors:
/usr/bin/ld: ../../lib/libopencv_videoio.so.4.5.3: undefined reference to `avcodec_get_context_defaults3'
/usr/bin/ld: ../../lib/libopencv_videoio.so.4.5.3: undefined reference to `av_lockmgr_register'
/usr/bin/ld: ../../lib/libopencv_videoio.so.4.5.3: undefined reference to `av_register_all'
I'm new to Linux, so I'm not exactly sure how to get started troubleshooting this. I believe I have ffmpeg correctly compiled and installed.
Here's the steps I use:
Configure ffmpeg:
sudo ./configure \
--prefix=/usr \
--extra-ldflags="-latomic" \
--enable-shared \
--extra-libs='-lpthread -lm' \
--ld=g++ \
--enable-gpl \
--disable-debug \
--enable-nonfree \
--enable-libx264 \
--enable-omx \
--enable-omx-rpi \
--enable-gnutls \
--enable-libfreetype \
--enable-libmp3lame
Then build it:
sudo make -j4
Then install it as a package: (so opencv cmake will detect it)
sudo checkinstall -y --deldoc=yes --pkgversion=9999 --pkgname=ffmpeg
Then configure opencv (ffmpeg is detected)
sudo cmake ../opencv_sources -D CMAKE_BUILD_TYPE=RELEASE \
-D OPENCV_EXTRA_MODULES_PATH= $PWD/../opencv_contrib/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=ON \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D CMAKE_SHARED_LINKER_FLAGS='-latomic -L/usr/lib' \
-D WITH_V4L=ON \
-D WITH_QT=OFF \
-D BUILD_EXAMPLES=OFF \
-D CPU_BASELINE=NATIVE \
-D CMAKE_INSTALL_PREFIX="$HOME/opencv_build" \
-D BUILD_opencv_apps=OFF \
-D BUILD_opencv_python2=OFF \
-D BUILD_SHARED_LIBS=ON \
-D WITH_FFMPEG=ON
Then build opencv:
sudo make -j4
And this is where I get linking errors.
I checked in /usr/lib and the .so files appear to be there:
ls /usr/lib | grep libav
libavcodec.a
libavcodec.so
libavcodec.so.59
libavcodec.so.59.4.101
libavdevice.a
libavdevice.so
libavdevice.so.59
libavdevice.so.59.0.100
libavfilter.a
libavfilter.so
libavfilter.so.8
libavfilter.so.8.1.103
libavformat.a
libavformat.so
libavformat.so.59
libavformat.so.59.4.101
libavutil.a
libavutil.so
libavutil.so.57
libavutil.so.57.3.100
How do check where opencv is looking when linking? And is there a way I can check the shared libraries that ffmpeg generated to make sure they work?
The ffmpeg version is: git-2021-08-10-c245963
And opencv is 4.5.3-dev
TL;DR:
I was compiling the master branch of ffmpeg. This version removed some deprecated functions and was incompatible with my opencv version. Or at least the build tests failed. By switching to the release/4.4 branch and repeating my previous build steps I was able to successfully build opencv.
Details:
I was able to determine that it's not a linking problem. I wrote a short program that calls avcodec_get_context_defaults3(...), as well as avcodec_version(), which is another function that should be in there. Upon linking libavcodec.so, the avcodec_version() is found, but avcodec_get_context_defaults3() is not. Therefore I believe this is a version compatibility issue between ffmpeg and opencv.
I then confirmed that the function was removed from ffmpeg. The latest version does not have it, old versions do. I used git's search function and found this commit:
Author: Andreas Rheinhardt <andreas.rheinhardt#gmail.com>
Date: Thu Feb 25 20:37:24 2021 +0100
avcodec: Remove deprecated avcodec_get_context_defaults3
Deprecated in 04fc8e24a091ed1d77d7a3c0cbcfe60baec19a9f.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt#gmail.com>
Signed-off-by: James Almer <jamrial#gmail.com>
I switched to the release/3.4 branch of FFMPEG and repeated the steps. But that was missing some other things. I repeated the steps a 3rd time with release/4.4 and that worked.
The command I used to download the correct branch was this:
sudo git clone https://github.com/FFmpeg/FFmpeg --branch release/4.4 --depth 1 ffmpeg_sources

using opencv::cuda::demosaicing() without cuda sdk installed

this is my make file,
from Cuda image processing module, I would like to use demosaicing()
I'm am building cuda on my own. and do not want to use the cuda sdk
i'm using openCV 3.0.0 version
default:
#echo Makefile targets are clean, build and rebuild
BUILD_DIR=build_dir
clean:
# Do nothing so that developers can do "clean" or "rebuild" solution without
# forcing to rebuild also OpenCV. Below is documented what the "clean" should do
# if it were to be enabled.
# -rmdir /Q /S $(BUILD_DIR)
build: $(BUILD_DIR)\lib\$(CONFIGURATION)
rebuild: clean build
$(BUILD_DIR)\lib\$(CONFIGURATION): $(BUILD_DIR)\OpenCV.sln
-cd $(BUILD_DIR)
devenv OpenCV.sln /build "$(CONFIGURATION)|x64" /project ALL_BUILD
devenv OpenCV.sln /build "$(CONFIGURATION)|x64" /project INSTALL
$(BUILD_DIR)\OpenCV.sln:
if not exist $(BUILD_DIR) (mkdir $(BUILD_DIR) )
cd $(BUILD_DIR)
cmake \
-D BUILD_SHARED_LIBS=FALSE \
-D BUILD_opencv_apps=FALSE \
-D BUILD_DOCS=FALSE \
-D BUILD_PACKAGE=FALSE \
-D BUILD_PERF_TESTS=FALSE \
-D BUILD_TESTS=FALSE \
-D BUILD_FAT_JAVA_LIB=FALSE \
-D BUILD_opencv_python2=FALSE \
-D BUILD_opencv_python3=FALSE \
-D BUILD_WITH_STATIC_CRT=OFF \
-D WITH_FFMPEG=OFF \
-D WITH_IPP=OFF \
-D WITH_OPENCL=OFF \
-D BUILD_CUDA_STUBS=ON \
-G "Visual Studio 12 2013 Win64" \
$(SolutionDir)\3rdparty\opencv
the error i'm getting is
..opencv\modules\cudaimgproc\src\histogram.cpp(58): error C2244: 'histEven' : unable to match function definition to an existing declaration

Compiling OpenCV with Contrib and C++11 Support?

I want to compile opencv from source on ubuntu 16.04.
I already did this successfully a couple of times before.
I am following this tutorial from pyimagesearch.
Normally this works very well, but this time I am getting the following error for the contrib module text.
[ 27%] Generating precomp.hpp.gch/opencv_text_RELEASE.gch In file
included from /usr/include/c++/5/cinttypes:35:0,
from /usr/local/include/tesseract/host.h:30,
from /usr/local/include/tesseract/serialis.h:26,
from /usr/local/include/tesseract/baseapi.h:37,
from /home/rvq/github/opencv-3.2.0/build/modules/text/precomp.hpp:51:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file
requires compiler and library support for the ISO C++ 2011 standard.
This support must be enabled with the -std=c++11 or -std=gnu++11
compiler options. #error This file requires compiler and library
support \ ^
[ 27%] Built target pch_Generate_opencv_saliency
Does somebody know how to resolve this?
Adding -D ENABLE_PRECOMPILED_HEADERS=OFF \ to CMake command resolved the issue.
Complete CMake Command:
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=~/github/opencv_contrib-3.2.0/modules \
-D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
-D BUILD_EXAMPLES=ON ..

Failed to link osmesa correctly

Mesa version = 12.0.1
Tried version before this as well.
At link time this error comes up: /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/libGL.so: undefined reference to _glapi_tls_Dispatch'.
The script i am using to install mesa:
#!/bin/bash
make -j4 distclean # if in an existing build
autoreconf -fi
./configure \
CXXFLAGS="-O2 -g -DDEFAULT_SOFTWARE_DEPTH_BITS=31" \
CFLAGS="-O2 -g -DDEFAULT_SOFTWARE_DEPTH_BITS=31" \
--disable-xvmc \
--disable-glx \
--disable-dri \
--with-dri-drivers="" \
--with-gallium-drivers="swrast" \
--enable-texture-float \
--enable-shared-glapi \
--disable-egl \
--with-egl-platforms="" \
--enable-gallium-osmesa \
--enable-llvm-shared-libs=yes \
--enable-gallium-llvm=yes \
--prefix=/home/ec2-user/new-mesa/mesaBuild/
make -j2
make -j4 install
After installation :
Added prefix(defined in script) to /etc/ld.so.conf' and ran ldconfig
Then in link command: -Lprefix -lOSMesa
What am i doing wrong?