CMake交叉编译无法找到库 [英] Cmake cross compile cant find library

查看:1244
本文介绍了CMake交叉编译无法找到库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CMake在BeagleBone Black上编译OpenCV,但找不到gstream之类的库.我在BBB上本地运行cmake,它显示 那rootfs有gstream.如何告诉CMake在正确的路径中搜索?

i am tring to compile OpenCV on BeagleBone Black with CMake, but it can't find some libraries like gstream. I run cmake natively on BBB and it showed that rootfs has gstream. how can i tell CMake to search in Correct path ?

我的toolchane.cmake

My toolchane.cmake

    set(CMAKE_SYSTEM_NAME Linux)
    set(CMAKE_SYSTEM_VERSION 4.4.9-ti-r25)
    set(CMAKE_SYSTEM_PROCESSOR armv7l)

    set(GCC_COMPILER_VERSION "4.7" CACHE STRING "GCC Compiler version")

####### Architecture ################
set(FLOAT_ABI_SUFFIX "hf")
set(ENABLE_NEON TRUE)

###### Link Compile Path ##############
set(ARM_SYS_ROOT_PATH /mnt/BBB) 

set(ARM_STD_USR_PATH ${ARM_SYS_ROOT_PATH}/usr )
set(ARM_STD_LIB_PATH ${ARM_SYS_ROOT_PATH}/usr/lib )
set(ARM_SYS_LIB_PATH ${ARM_SYS_ROOT_PATH}/lib )
set(ARM_STD_INC_PATH ${ARM_SYS_ROOT_PATH}/usr/include )
set(GCC_MACHINE_DUMP arm-linux-gnueabihf)
set(CMAKE_INSTALL_PREFIX ${ARM_SYS_ROOT_PATH}/usr/local/OpenCV ) ## install Path

set(CMAKE_SYSROOT ${ARM_LINUX_SYSROOT})


set(CMAKE_FIND_ROOT_PATH  ${CMAKE_SYSROOT}) ##searchs in X/lib and X/usr/lib
set(CMAKE_INCLUDE_PATH  ${ARM_STD_INC_PATH} ; ${ARM_STD_INC_PATH}/${GCC_MACHINE_DUMP} )
set(CMAKE_LIBRARY_PATH  ${ARM_STD_LIB_PATH} ; ${ARM_STD_LIB_PATH}/${GCC_MACHINE_DUMP} ; ${ARM_SYS_LIB_PATH} ; ${ARM_SYS_LIB_PATH}/${GCC_MACHINE_DUMP})
set(CMAKE_PROGRAM_PATH  ${ARM_SYS_ROOT_PATH}/usr/bin})
##### Install path ##############
set(CMAKE_INSTALL_PREFIX ${ARM_STD_USR_PATH})

##### Other ###########
set(CMAKE_COLOR_MAKEFILE ON)
set(PKG_CONFIG_EXECUTABLE /usr/bin/pkg-config)
################# Compiler ##########
set(CMAKE_C_COMPILER "/usr/gcc-linaro-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-gcc")
set(CMAKE_CXX_COMPILER "/usr/gcc-linaro-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-g++")
set(CMAKE_AR "/usr/gcc-linaro-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-ar")
set(CMAKE_RANLIB "/usr/gcc-linaro-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-ranlib")
set(CMAKE_LINKER "/usr/gcc-linaro-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-ld")

###  C and Cxx Flags ########################
set(DCMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS           "-isystem /mnt/BBB/lib:/mnt/BBB/lib/arm-linux-gnueabihf:/mnt/BBB/usr/lib/arm-linux-gnueabihf"                    CACHE STRING "c++ flags")
set(CMAKE_C_FLAGS             "-isystem /mnt/BBB/lib:/mnt/BBB/lib/arm-linux-gnueabihf:/mnt/BBB/usr/lib/arm-linux-gnueabihf"                    CACHE STRING "c flags")
set(CMAKE_SHARED_LINKER_FLAGS "-isystem /mnt/BBB/lib:/mnt/BBB/lib/arm-linux-gnueabihf:/mnt/BBB/usr/lib/arm-linux-gnueabihf"                    CACHE STRING "shared linker flags")
set(CMAKE_MODULE_LINKER_FLAGS "-isystem /mnt/BBB/lib:/mnt/BBB/lib/arm-linux-gnueabihf:/mnt/BBB/usr/lib/arm-linux-gnueabihf"                    CACHE STRING "module linker flags")
set(CMAKE_EXE_LINKER_FLAGS    "-Wl,-z,-rpath-link"  CACHE STRING "executable linker flags")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")

set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now ${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS    "-Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now ${CMAKE_EXE_LINKER_FLAGS}")

########### Macro to Limit Find path in host and targert ###################
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

交叉编译CMake的结果

Result of Cross Compile CMake

General configuration for OpenCV 2.4.11 =====================================
  Version control:               unknown

  Platform:
    Host:                        Linux 3.16.0-38-generic x86_64
    Target:                      Linux 4.4.9-ti-r25 armv7l
    CMake:                       2.8.12.2
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                /usr/gcc-linaro-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-g++  (ver 4.7.3)
    C++ flags (Release):         -isystem /mnt/BBB/lib:/mnt/BBB/lib/arm-linux-gnueabihf:/mnt/BBB/usr/lib/arm-linux-gnueabihf -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -isystem /mnt/BBB/lib:/mnt/BBB/lib/arm-linux-gnueabihf:/mnt/BBB/usr/lib/arm-linux-gnueabihf -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/gcc-linaro-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-gcc
    C flags (Release):           -isystem /mnt/BBB/lib:/mnt/BBB/lib/arm-linux-gnueabihf:/mnt/BBB/usr/lib/arm-linux-gnueabihf -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -isystem /mnt/BBB/lib:/mnt/BBB/lib/arm-linux-gnueabihf:/mnt/BBB/usr/lib/arm-linux-gnueabihf -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -isystem /mnt/BBB/lib:/mnt/BBB/lib/arm-linux-gnueabihf:/mnt/BBB/usr/lib/arm-linux-gnueabihf
    Linker flags (Debug):        -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -isystem /mnt/BBB/lib:/mnt/BBB/lib/arm-linux-gnueabihf:/mnt/BBB/usr/lib/arm-linux-gnueabihf
    Precompiled headers:         YES

  OpenCV modules:
    To be built:                 core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu ocl nonfree contrib stitching superres ts videostab
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 androidcamera dynamicuda java python viz

  GUI: 
    QT:                          NO
    GTK+ 2.x:                    YES (ver 2.24.23)
    GThread :                    YES (ver 2.40.2)
    GtkGlExt:                    NO
    OpenGL support:              NO
    VTK support:                 NO

  Media I/O: 
    ZLib:                        /mnt/BBB/usr/lib/arm-linux-gnueabihf/libz.so (ver 1.2.8)
    JPEG:                        /mnt/BBB/usr/lib/arm-linux-gnueabihf/libjpeg.so (ver )
    PNG:                         /mnt/BBB/usr/lib/arm-linux-gnueabihf/libpng.so (ver 1.2.50)
    TIFF:                        /mnt/BBB/usr/lib/arm-linux-gnueabihf/libtiff.so (ver 42 - 4.0.3)
    JPEG 2000:                   /mnt/BBB/usr/lib/arm-linux-gnueabihf/libjasper.so (ver 1.900.1)
    OpenEXR:                     /mnt/BBB/usr/lib/arm-linux-gnueabihf/libImath.so /mnt/BBB/usr/lib/arm-linux-gnueabihf/libIlmImf.so /mnt/BBB/usr/lib/arm-linux-gnueabihf/libIex.so /mnt/BBB/usr/lib/arm-linux-gnueabihf/libHalf.so /mnt/BBB/usr/lib/arm-linux-gnueabihf/libIlmThread.so (ver 1.6.1)

  Video I/O:
    DC1394 1.x:                  NO
    DC1394 2.x:                  NO
    FFMPEG:                      YES
      codec:                     YES (ver 54.35.0)
      format:                    YES (ver 54.20.4)
      util:                      YES (ver 52.3.0)
      swscale:                   YES (ver 2.1.1)
      gentoo-style:              YES
    GStreamer:                   NO
    OpenNI:                      NO
    OpenNI PrimeSensor Modules:  NO
    PvAPI:                       NO
    GigEVisionSDK:               NO
    UniCap:                      NO
    UniCap ucil:                 NO
    V4L/V4L2:                    NO/YES
    XIMEA:                       NO
    Xine:                        NO

  Other third-party libraries:
    Use IPP:                     NO
    Use Eigen:                   NO
    Use TBB:                     NO
    Use OpenMP:                  NO
    Use GCD                      NO
    Use Concurrency              NO
    Use C=:                      NO
    Use Cuda:                    NO
    Use OpenCL:                  YES

  OpenCL:
    Version:                     dynamic
    Include path:                /home/arash/Desktop/opencv-2.4.11/3rdparty/include/opencl/1.2
    Use AMD FFT:                 NO
    Use AMD BLAS:                NO

  Python:
    Interpreter:                 /usr/bin/python2 (ver 2.7.6)

  Java:
    ant:                         NO
    JNI:                         NO
    Java tests:                  NO

  Documentation:
    Build Documentation:         NO
    Sphinx:                      NO
    PdfLaTeX compiler:           NO
    Doxygen:                     NO

  Tests and samples:
    Tests:                       YES
    Performance tests:           YES
    C/C++ Examples:              NO

  Install path:                  /mnt/BBB/usr

  cvconfig.h is in:              /home/arash/Desktop/opencv-2.4.11/buildBBBnew

在BBB目标上原生CMake的结果

Result of Native CMake On BBB Target

-- General configuration for OpenCV 2.4.11 =====================================
--   Version control:               unknown
-- 
--   Platform:
--     Host:                        Linux 4.4.9-ti-r25 armv7l
--     CMake:                       3.4.1
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               Release
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/c++  (ver 4.9.2)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):
--     Linker flags (Debug):
--     Precompiled headers:         YES
-- 
--   OpenCV modules:
--     To be built:                 core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu ocl nonfree contrib python stitching superres ts videostab
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 androidcamera dynamicuda java viz
-- 
--   GUI: 
--     QT:                          NO
--     GTK+ 2.x:                    YES (ver 2.24.25)
--     GThread :                    YES (ver 2.42.1)
--     GtkGlExt:                    NO
--     OpenGL support:              NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/arm-linux-gnueabihf/libz.so (ver 1.2.8)
--     JPEG:                        /usr/lib/arm-linux-gnueabihf/libjpeg.so (ver )
--     PNG:                         /usr/lib/arm-linux-gnueabihf/libpng.so (ver 1.2.50)
--     TIFF:                        /usr/lib/arm-linux-gnueabihf/libtiff.so (ver 42 - 4.0.3)
--     JPEG 2000:                   /usr/lib/arm-linux-gnueabihf/libjasper.so (ver 1.900.1)
--     OpenEXR:                     /usr/lib/arm-linux-gnueabihf/libImath.so /usr/lib/arm-linux-gnueabihf/libIlmImf.so /usr/lib/arm-linux-gnueabihf/libIex.so /usr/lib/arm-linux-gnueabihf/libHalf.so /usr/lib/arm-linux-gnueabihf/libIlmThread.so (ver 1.6.1)
-- 
--   Video I/O:
--     DC1394 1.x:                  NO
--     DC1394 2.x:                  YES (ver 2.2.3)
--     FFMPEG:                      YES
--       codec:                     YES (ver 56.1.0)
--       format:                    YES (ver 56.1.0)
--       util:                      YES (ver 54.3.0)
--       swscale:                   YES (ver 3.0.0)
--       gentoo-style:              YES
--     GStreamer:                   
--       base:                      YES (ver 1.4.4)
--       video:                     YES (ver 1.4.4)
--       app:                       YES (ver 1.4.4)
--       riff:                      YES (ver 1.4.4)
--       pbutils:                   YES (ver 1.4.4)
--     OpenNI:                      NO
--     OpenNI PrimeSensor Modules:  NO
--     PvAPI:                       NO
--     GigEVisionSDK:               NO
--     UniCap:                      NO
--     UniCap ucil:                 NO
--     V4L/V4L2:                    Using libv4l1 (ver 1.6.0) / libv4l2 (ver 1.6.0)
--     XIMEA:                       NO
--     Xine:                        NO
-- 
--   Other third-party libraries:
--     Use IPP:                     NO
--     Use Eigen:                   NO
--     Use TBB:                     NO
--     Use OpenMP:                  NO
--     Use GCD                      NO /mnt/BBB/usr/lib/mnt/BBB/usr/lib/arm-linux-gnueabihf/mnt/BBB/lib/mnt/BBB/lib/arm-linux-gnueabihf

--     Use Concurrency              NO
--     Use C=:                      NO
--     Use Cuda:                    NO
--     Use OpenCL:                  YES
-- 
--   OpenCL:
--     Version:                     dynamic
--     Include path:                /home/debian/Desktop/opencv-2.4.11/3rdparty/include/opencl/1.2
--     Use AMD FFT:                 NO
--     Use AMD BLAS:                NO
-- 
--   Python:
--     Interpreter:                 /usr/bin/python2 (ver 2.7.9)
--     Libraries:                   /usr/lib/arm-linux-gnueabihf/libpython2.7.so (ver 2.7.9)
--     numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2)
--     packages path:               lib/python2.7/dist-packages
-- 
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java tests:                  NO
-- 
--   Documentation:
--     Build Documentation:         NO
--     Sphinx:                      NO
--     PdfLaTeX compiler:           NO
--     Doxygen:                     NO
-- 
--   Tests and samples:
--     Tests:                       YES
--     Performance tests:           YES
--     C/C++ Examples:              NO
-- 
--   Install path:                  /usr/local
-- 
--   cvconfig.h is in:              /home/debian/Desktop/opencv-2.4.11/build
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/debian/Desktop/opencv-2.4.11/build

推荐答案

感谢@Tsyvarev,问题出在pkg-config.在主机上,我有:

Thanks to @Tsyvarev, The problem was pkg-config. in host i have:

myPC:~$ pkg-config --libs gstreamer-1.0
Package gstreamer-1.0 was not found in the pkg-config search path.

但在目标BeagleBone中:

but in target BeagleBone :

beaglebone:~# pkg-config --modversion  gstreamer-1.0
1.4.4

和目标中.pc文件的路径为:

and the path for .pc files in target are :

   beaglebone:~# pkg-config --variable pc_path pkg-config
    /usr/local/lib/arm-linux-gnueabihf/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig

[错误的方式!] 所以我只是将这些带有/mnt/BBB前缀(我的目标rootfs)的路径添加到主机的pkg-config环境中并运行cmake,一切都得到了公认:

[Wrong Way !] so i simply added these path with prefix of /mnt/BBB (my target rootfs) to pkg-config environment of host and run cmake, everything well recognized :

myPC:~$ export PKG_CONFIG_PATH=/mnt/BBB/usr/local/lib/arm-linux-gnueabihf/pkgconfig:/mnt/BBB/usr/local/lib/pkgconfig:/mnt/BBB/usr/local/share/pkgconfig:/mnt/BBB/usr/lib/arm-linux-gnueabihf/pkgconfig:/mnt/BBB/usr/lib/pkgconfig:/mnt/BBB/usr/share/pkgconfig
myPC:~$ cmake-gui

根据此链接,我需要创建 pkg-config包装器脚本. 在我的工具链目录中,我有 arm-linux-gnueabihf-pkg-config-real ,然后我应该将其脚本修改为此:

According to This link, i need to create pkg-config wrapper script. in my toolchain Directory i have arm-linux-gnueabihf-pkg-config-real and then i should modify its script to this:

#!/bin/sh
#
# Wrapper script that calls the real pkg-config with the relocated
# sysroot location
#
set -e

GCC="${0%%-pkg-config}-gcc" 
MACHINE=`"$GCC" -dumpmachine`
SYSROOT=`"$GCC" -print-sysroot`
SYSROOT=/mnt/BBB              #My modification
export PKG_CONFIG_DIR=
export PKG_CONFIG_LIBDIR="${SYSROOT}/usr/lib/${MACHINE}/pkgconfig":"${SYSROOT}/usr/lib/pkgconfig":"${SYSROOT}/usr/share/pkgconfig"
export PKG_CONFIG_SYSROOT_DIR="${SYSROOT}"

exec "$0-real" "$@"

然后在 toolchain.cmake

set(PKG_CONFIG_EXECUTABLE /usr/gcc-linaro-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-pkg-config)

一切都很好...

这篇关于CMake交叉编译无法找到库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆