MrE
MrE

Reputation: 20798

cross-compile with dependencies: how to get target dependencies on host?

I've been struggling to cross-compile OpenCV for arm on my x64 dual Xeon running Ubuntu 16.04

I understand how cross-compiler work, and it's fine compiling a simple project, but OpenCV has lots of dependencies.

I do not understand how to load these dependencies (headers only?) on the host used to cross-compile

I have tried

dpkg --add-architecture armhf

and I have tried adding the urls in the sources.list to install the dependencies.

I have tried installing dependencies with the :armhf suffix but these dependencies tend to have dependencies themselves and I end up with error of the form: cannot install

I tried also to use

apt-get build-dep --download-only <dependency>:armhf

but that just didn't seem to help.

So, first I'd like to understand:

Sorry if it's vague; I'm just not sure where to look for this. Every tutorial I see on cross-compiling leaves dependencies aside, and the OpenCV project explanation on cross-compiling assumes the reader already knows all this...

Thanks for help

EDIT

I added my solution below, but I don't find this ideal since it requires to install everything on the target first. Obviously, the dependencies are needed on the target anyways, but there is no need for all the dev libraries and headers for runtime

So I'm still looking for a better solution

Upvotes: 4

Views: 1964

Answers (1)

MrE
MrE

Reputation: 20798

I managed to cross-compile, but it was a little painful.

The only way I found so far to get the dependencies on the compiling host, was to simply copy the files from the target where I installed them.

The folders needed are mostly

  • /usr (especially usr/include, /usr/lib and /usr/bin)
  • /lib
  • /opt (if you had any special library setup there)

You can tar those folders and copy them over to the host, or use rsync.

After that, you have to make sure to configure the path with cmake.

I copied stuff to a folder called sysroot-chip at the same level as opencv and my build dir is also at the same level (outside of opencv)

and added the following flags to cmake:

-D INCLUDE_DIRECTORIES=../sysroot-chip/usr/lib \
-D INCLUDE_DIRECTORIES=../sysroot-chip/usr/bin \
-D INCLUDE_DIRECTORIES=../sysroot-chip/opt/lib \
-D INCLUDE_DIRECTORIES=../sysroot-chip/lib \
-D PYTHON2_INCLUDE_PATH=../sysroot-chip/usr/include/python2.7 \
-D PYTHON2_LIBRARIES=../sysroot-chip/usr/lib/python2.7 \
-D PYTHON2_NUMPY_INCLUDE_DIRS=../sysroot-chip/usr/lib/python2.7/dist-packages \
-D PYTHON3_INCLUDE_PATH=../sysroot-chip/usr/include/python3.4 \
-D PYTHON3_LIBRARIES=../sysroot-chip/usr/lib/python3.4 \
-D PYTHON3_NUMPY_INCLUDE_DIRS=../sysroot-chip//usr/lib/python3.4/dist-packages \

along with the cross compiling toolchain flag:

-D CMAKE_TOOLCHAIN_FILE=../opencv-3.1.0/platforms/linux/arm-gnueabi.toolchain.cmaketoolchain.cmake \

Upvotes: 1

Related Questions