Cross-compile for ARM

asked 2019-08-14 10:35:07 -0600

paubau gravatar image

updated 2019-08-19 17:02:18 -0600

Hi,

I'm trying to cross-build OpenCV for ARM using a Docker image, but I'm getting linking errors. Does anyone have an idea how to resolve those linking errors ?

../../lib/libopencv_core.so.4.1.1: undefined reference to `gzeof'
../../lib/libopencv_core.so.4.1.1: undefined reference to `gzrewind'
../../lib/libopencv_core.so.4.1.1: undefined reference to `gzopen'
../../lib/libopencv_core.so.4.1.1: undefined reference to `gzclose'
../../lib/libopencv_core.so.4.1.1: undefined reference to `gzgets'
../../lib/libopencv_core.so.4.1.1: undefined reference to `gzputs'
collect2: error: ld returned 1 exit status
apps/version/CMakeFiles/opencv_version.dir/build.make:84: recipe for target 'bin/opencv_version' failed

with cmake command:

cmake \
   -D CMAKE_BUILD_TYPE=RELEASE \
   -D OPENCV_EXTRA_MODULES_PATH=/opencv_contrib/modules/ \
   -D ENABLE_NEON=ON \
   -D ENABLE_VFPV3=ON \
   -D ENABLE_LTO=ON \
   -D SOFTFP=ON \
   -D CPU_BASELINE=NEON \
   -D WITH_TBB=ON \
   -D WITH_OPENCL=ON \
   -D WITH_GSTREAMER=ON \
   -D BUILD_EXAMPLES=OFF \
   -D BUILD_TESTS=OFF \
   -D BUILD_SHARED=OFF \
   -D BUILD_ZLIB=ON \
   -D WITH_CAROTENE=OFF \
   -D WITH_ITT=OFF \
   -D WITH_CUDA=OFF \
   -D OPENCV_EXTRA_EXE_LINKER_FLAGS=-lzlib \
   -D ENABLE_PRECOMPILED_HEADERS=OFF \
   -D OPENCV_ENABLE_NONFREE=ON \
   -D CMAKE_TOOLCHAIN_FILE=../platforms/linux/arm-gnueabi.toolchain.cmake \
   -D CMAKE_SYSTEM_PROCESSOR=armv7l \
   -D CMAKE_C_COMPILER=arm-linux-gnueabihf-gcc \
   -D CMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ \
   -D BUILD_opencv_python2=OFF \
   -D BUILD_opencv_python3=ON \
   -D PYTHON_EXECUTABLE=$(which python3) \
   -D PYTHON_LIBRARY=$(python3 -c "from distutils.sysconfig import get_config_var;from os.path import dirname,join ; print(join(dirname(get_config_var('LIBPC')),get_config_var('LDLIBRARY')))") \
   -D PYTHON_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
   -D PYTHON3_NUMPY_INCLUDE_DIRS=$(python3 -c "import numpy; print(numpy.get_include())") ..

Thanks for helping

edit retag flag offensive close merge delete

Comments

You have to make sure that zlib is correcly linked before you start linking OpenCV itself. It seems as if -D OPENCV_EXTRA_EXE_LINKER_FLAGS=-lzlib the compiler flag is added after the dependency on opencv_core and thus the build doesn't know it is provided. Does cross compile for ARM work with static linking? In that case linking order is VERY important.

StevenPuttemans gravatar imageStevenPuttemans ( 2019-08-20 06:36:02 -0600 )edit

So zlib is installed but apparently it is still not found by the linker during make. So I tough adding the extra liker flag env, could help to detect zlib, but it didn't. I probably could also delete the flag I guess.

As for the static linking. I'm not sure how to influence the linking behavior during the build process.

paubau gravatar imagepaubau ( 2019-08-20 06:47:29 -0600 )edit

I think the reason for the error might be some issue with the pkg-config, have a lot of plugin needed to handle lto object warnings and also some CMake Warnings ocv_check_modules .. can't find library. And added OPENCV_ENABLE_PKG_CONFIG=ONand PKG_CONFIG_EXECUTABLE=/usr/bin/arm-linux-gnueabihf-pkg-config like described here + export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig which contains all the pc files of the libraries. However I'm still searching for a way to successfully compile it.

paubau gravatar imagepaubau ( 2019-08-20 08:28:14 -0600 )edit

Somethink like /usr/bin/arm-linux-gnueabihf-pkg-config --cflags harfbuzz does seem to work however and returns -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include

paubau gravatar imagepaubau ( 2019-08-20 08:45:24 -0600 )edit

Its somewhat out of my expertise and not really sure how to help you further...

StevenPuttemans gravatar imageStevenPuttemans ( 2019-08-21 04:52:58 -0600 )edit