Ask Your Question
3

Cross compile OpenCV but failed to find 3rd party library

asked 2013-02-08 07:58:42 -0600

rickyzhang gravatar image

Hi,

I want to cross compile customized OpenCV for arm board in my Linux x86 host machine. I followed tutorial here http://processors.wiki.ti.com/index.php/Building_OpenCV_for_ARM_Cortex-A8

But set( CMAKE_FIND_ROOT_PATH "YOUR_LIB_PATH_LIST" ) can't find all my library listed in "YOUR_LIB_PATH_LIST".

I googled CMAKE about CMAKE_FIND_ROOT_PATH in (http://www.vtk.org/Wiki/CMake_Cross_Compiling). It says it will find "YOUR_LIB_PATH_LIST"/lib, "YOUR_LIB_PATH_LIST"/usr/lib, /lib and /usr/lib. The statement in cmake doc also implies that you can add additional path. But I tried. The additional path doesn't work.

I use NFS to mount library folder to my host machine. I can managed to make target machine /lib and /usr/lib accessible in CMAKE_FIND_ROOT_PATH by some tricks. But I can't make /usr/local/lib works.

Any comments will be appreciated.

edit retag flag offensive close merge delete

Comments

1

I chased the macro CHECK_MODULE. It used pkg-config to look up library. It turns out that it ran target machine pkg-config binary in host machine.

I came up a quick solution:

  1. Modify cmake/OpenCVFindPkgConfig.cmake ... find_program(PKG_CONFIG_EXECUTABLE NAMES pkg-config PATHS /usr/bin DOC "pkg-config executable" NO_CMAKE_FIND_ROOT_PATH)

  2. Point host machine pkg-config path to target machine.

export PKG_CONFIG_PATH=/opt/Hackberryfs/usr/lib/pkgconfig:/opt/Hackberryfs/usr/local/lib/pkgconfig:/opt/Hackberryfs/usr/lib/arm-linux-gnueabihf/pkgconfig

However, I ran pkg-config. It is not smart enough to deal with cross compile env. I tried pkg-config gstreamer-0.10 in host machine. It return absolute path in target machine.

Anyway, the problem is not resolved.

rickyzhang gravatar imagerickyzhang ( 2013-02-08 12:02:42 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
2

answered 2013-02-10 16:25:43 -0600

rickyzhang gravatar image

updated 2013-02-10 16:27:54 -0600

To be more specific, I'm using linaro toolchain. I used NFS to mount target machine /usr and /lib to my host machine /opt/Hackberryfs/usr and /opt/Hackberry/lib.

Progress I made so far: I can run cmake to find out all 3rd party library installed in my target machine except python.

Here is steps I did:

  1. Modify OpenCV-2.4.3/cmake/OpenCVFindPkgConfig.cmake ... find_program(PKG_CONFIG_EXECUTABLE NAMES pkg-config PATHS /usr/bin DOC "pkg-config executable" NO_CMAKE_FIND_ROOT_PATH)

  2. Change pkg-config env variables:

export SYSROOT=/opt/Hackberryfs

export PKG_CONFIG_SYSROOT_DIR=${SYSROOT}

export PKG_CONFIG_PATH=${SYSROOT}/usr/lib/pkgconfig:${SYSROOT}/usr/local/lib/pkgconfig:${SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig:${SYSROOT}/usr/share/pkgconfig

  1. Use the following toolchain.cmake

    set( CMAKE_SYSTEM_PROCESSOR arm )

    set( CMAKE_C_COMPILER /opt/gcc-linaro-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc )

    set( CMAKE_CXX_COMPILER /opt/gcc-linaro-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ )

    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)

    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

    set(CMAKE_FIND_ROOT_PATH /opt/Hackberryfs /opt/Hackberryfs/usr/local/lib )

  2. Disable python support when running ccmake.

Conclusion:

  1. I looked into OpenCV-2.4.3/cmake/OpenCVDetectPython.cmake. It doesn't make sense to me that it tried to find host machine python. I'm not so sure how it works.

  2. I got linking error when compiling OpenCV. I looked into issues. It can't find target rule for libz.so. I'm scratching my head to take a look into build.cmake file. But auto-generated file from CMake is way too complicated to debug.

It is a pain in the ass to do cross compile. It already wasted me two days to figure out how cmake. For now, I'd live with arm board to do native compiling. I'm done with it.

edit flag offensive delete link more

Comments

Hello, did you manage to solve this problem? I'm getting the same libz error in CMake and I have a very similar setup and toolchain file. I'm not able to get it to find the right libz.

scorpiodawg gravatar imagescorpiodawg ( 2014-06-25 19:20:43 -0600 )edit
0

answered 2013-02-08 13:27:58 -0600

Some days ago cross compilation for ARM support was added to OpenCV branch 2.4. You can find cmake toolchain in project git in platform/linux folder. Here is my branch with arm-nonlinux-gnueabi toolchain. To use arm-nonlinux-gnueabi toolchain set -DCROSS_COMPILER_PATH=(path to compiler folder) cmake option.

edit flag offensive delete link more

Comments

I read your toolchain.make. How can you resolve pkg-config between host and target machine?

For example, when it runs zlib:

pkg-config zlib --cflags --libs

It returns absolute path of target machine. But in fact it should point to NFS path in host machine.

I used tricks below override the root directory in pkg-config:

Export

export SYSROOT=/opt/Hackberryfs

export PKG_CONFIG_SYSROOT_DIR=${SYSROOT}

export PKG_CONFIG_PATH=${SYSROOT}/usr/lib/pkgconfig:${SYSROOT}/usr/local/lib/pkgconfig:${SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig:${SYSROOT}/usr/share/pkgconfig

rickyzhang gravatar imagerickyzhang ( 2013-02-08 22:52:17 -0600 )edit
0

answered 2014-06-26 14:00:59 -0600

scorpiodawg gravatar image

I was hitting an issue related to finding libz.so. It turns out that this was a host library and not a target library that was required by ld. The host library was not found because I was on 64-bit Ubuntu and the toolchain was a 32-bit cross compiler toolchain.

This answer gave me the solution: http://stackoverflow.com/questions/3373995/usr-bin-ld-cannot-find-lz/5757638#5757638.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-02-08 07:58:42 -0600

Seen: 7,502 times

Last updated: Jun 26 '14