我一直在尝试在Ubuntu16.04上为Raspberry PI Zero (Raspbian stretch)构建OpenCV 3.3.1。我一直在遵循这里记录的步骤,主要的例外是,我没有使用来自https://github.com/raspberrypi/tools的工具,而是使用了https://github.com/HesselM/rpicross_notes 4.9.3,我使用了crosstool ng来构建一个GCC 6.3.0工具链,以匹配随Raspbian stretch提供的GCC版本。我已经在RaspberryPi Zero上安装了所有的OpenCV必备组件,然后复制了文件系统作为系统根目录。
CMake配置似乎可以工作,但在链接libopencv_freetype.so
时make构建失败,因为找不到harfbuzz和freetype库。
/opt/cross/x-tools/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/6.3.0/../../../../arm-unknown-linux-gnueabihf/bin/ld: cannot find -lfreetype
/opt/cross/x-tools/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/6.3.0/../../../../arm-unknown-linux-gnueabihf/bin/ld: cannot find -lharfbuzz
collect2: error: ld returned 1 exit status
modules/freetype/CMakeFiles/opencv_freetype.dir/build.make:97: recipe for target 'lib/libopencv_freetype.so.3.3.1' failed
这些库位于我的RaspberryPI系统中的usr/lib/arm-linux-gnueabihf中
-rw-r--r-- 1 dsnowdon dsnowdon 717178 Apr 27 2017 libfreetype.a
-rw-r--r-- 1 dsnowdon dsnowdon 909 Apr 27 2017 libfreetype.la
lrwxrwxrwx 1 dsnowdon dsnowdon 21 Apr 27 2017 libfreetype.so -> libfreetype.so.6.12.3
lrwxrwxrwx 1 dsnowdon dsnowdon 21 Apr 27 2017 libfreetype.so.6 -> libfreetype.so.6.12.3
-rw-r--r-- 1 dsnowdon dsnowdon 567844 Apr 27 2017 libfreetype.so.6.12.3
-rw-r--r-- 1 dsnowdon dsnowdon 739360 Jan 24 2017 libharfbuzz.a
lrwxrwxrwx 1 dsnowdon dsnowdon 24 Jan 24 2017 libharfbuzz.so -> libharfbuzz.so.0.10400.2
lrwxrwxrwx 1 dsnowdon dsnowdon 24 Jan 24 2017 libharfbuzz.so.0 -> libharfbuzz.so.0.10400.2
-rw-r--r-- 1 dsnowdon dsnowdon 551256 Jan 24 2017 libharfbuzz.so.0.10400.2
使用make VERBOSE=1构建会显示在运行以下命令时出现故障:
/usr/bin/cmake -E cmake_link_script CMakeFiles/opencv_freetype.dir/link.txt --verbose=1
这将生成以下内容:
/opt/cross/x-tools/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-g++ -fPIC -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include/arm-linux-gnueabihf -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/local/include -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG -shared -Wl,-soname,libopencv_freetype.so.3.3 -o ../../lib/libopencv_freetype.so.3.3.1 CMakeFiles/opencv_freetype.dir/src/freetype.cpp.o ../../lib/libopencv_imgproc.so.3.3.1 -ldl -lm -lpthread -lrt ../../3rdparty/lib/libtegra_hal.a -lfreetype -lharfbuzz ../../lib/libopencv_core.so.3.3.1
但是,如果我手动添加-L${RPI_ROOTFS}/usr/lib/arm-linux-gnueabihf
以提供以下内容,则链接可以正常工作:
/opt/cross/x-tools/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-g++ -L/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf -fPIC -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include/arm-linux-gnueabihf -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/local/include -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG -shared -Wl,-soname,libopencv_freetype.so.3.3 -o ../../lib/libopencv_freetype.so.3.3.1 CMakeFiles/opencv_freetype.dir/src/freetype.cpp.o ../../lib/libopencv_imgproc.so.3.3.1 -ldl -lm -lpthread -lrt ../../3rdparty/lib/libtegra_hal.a -lfreetype -lharfbuzz ../../lib/libopencv_core.so.3.3.1
这让我想到,也许pkg-config是以这样的方式调用的,它没有发出正确的libdir,所以我编写了一个包装器脚本来转储所有的pkg-config调用和结果。
#! /bin/bash
LOGFILE=/tmp/pkg-config-wrapper.log
basename="`basename "$0"`"
timestamp=$(date)
printf "${timestamp} ${basename} $@\nPKG_CONFIG_DIR=${PKG_CONFIG_DIR}\nPKG_CONFIG_LIBDIR=${PKG_CONFIG_LIBDIR}\nPKG_CONFIG_SYSROOT_DIR=${PKG_CONFIG_SYSROOT_DIR}\n" >> $LOGFILE
result=$(/usr/bin/pkg-config "$@")
printf "pkf-config = ${result}\n" >> $LOGFILE
echo $result
这是我在harfbuzz中发现的与链接相关的(我已经省略了pkg-config cflag的其他调用,对于freetype和gtk的简短调用):
Wed 8 Aug 06:33:54 BST 2018 pkg-config-wrapper.sh --exists
--print-errors --short-errors harfbuzz
PKG_CONFIG_DIR=
PKG_CONFIG_LIBDIR=:/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/usr/share/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/opt/vc/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR=/opt/software/raspberrypi/rpi-cross/rootfs
pkg-config =
Wed 8 Aug 06:33:54 BST 2018 pkg-config-wrapper.sh --modversion
harfbuzz
PKG_CONFIG_DIR=
PKG_CONFIG_LIBDIR=:/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/usr/share/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/opt/vc/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR=/opt/software/raspberrypi/rpi-cross/rootfs
pkg-config = 1.4.2
Wed 8 Aug 06:33:54 BST 2018 pkg-config-wrapper.sh --variable=prefix
harfbuzz
PKG_CONFIG_DIR=
PKG_CONFIG_LIBDIR=:/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/usr/share/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/opt/vc/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR=/opt/software/raspberrypi/rpi-cross/rootfs
pkg-config = /usr
Wed 8 Aug 06:33:54 BST 2018 pkg-config-wrapper.sh --variable=libdir
harfbuzz
PKG_CONFIG_DIR=
PKG_CONFIG_LIBDIR=:/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/usr/share/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/opt/vc/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR=/opt/software/raspberrypi/rpi-cross/rootfs
pkg-config = /usr/lib/arm-linux-gnueabihf
Wed 8 Aug 06:33:54 BST 2018 pkg-config-wrapper.sh --libs-only-l
harfbuzz
PKG_CONFIG_DIR=
PKG_CONFIG_LIBDIR=:/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/usr/share/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/opt/vc/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR=/opt/software/raspberrypi/rpi-cross/rootfs
pkg-config = -lharfbuzz
Wed 8 Aug 06:33:55 BST 2018 pkg-config-wrapper.sh --static
--libs-only-l harfbuzz
PKG_CONFIG_DIR=
PKG_CONFIG_LIBDIR=:/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/usr/share/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/opt/vc/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR=/opt/software/raspberrypi/rpi-cross/rootfs
pkg-config = -lharfbuzz -lglib-2.0 -lpcre -lgraphite2
Wed 8 Aug 06:33:55 BST 2018 pkg-config-wrapper.sh --libs-only-L
harfbuzz
PKG_CONFIG_DIR=
PKG_CONFIG_LIBDIR=:/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/usr/share/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/opt/vc/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR=/opt/software/raspberrypi/rpi-cross/rootfs
pkg-config = -L/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf
Wed 8 Aug 06:33:55 BST 2018 pkg-config-wrapper.sh --static
--libs-only-L harfbuzz
PKG_CONFIG_DIR=
PKG_CONFIG_LIBDIR=:/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/usr/share/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/opt/vc/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR=/opt/software/raspberrypi/rpi-cross/rootfs
pkg-config = -L/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf
Wed 8 Aug 06:33:55 BST 2018 pkg-config-wrapper.sh --libs
harfbuzz
PKG_CONFIG_DIR=
PKG_CONFIG_LIBDIR=:/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/usr/share/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/opt/vc/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR=/opt/software/raspberrypi/rpi-cross/rootfs
pkg-config = -L/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf -lharfbuzz
Wed 8 Aug 06:33:55 BST 2018 pkg-config-wrapper.sh --static
--libs harfbuzz
PKG_CONFIG_DIR=
PKG_CONFIG_LIBDIR=:/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/usr/share/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/opt/vc/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR=/opt/software/raspberrypi/rpi-cross/rootfs
pkg-config = -L/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf -lharfbuzz -lglib-2.0 -pthread -lpcre -pthread -lgraphite2
Wed 8 Aug 06:33:55 BST 2018 pkg-config-wrapper.sh --libs-only-other
harfbuzz
PKG_CONFIG_DIR=
PKG_CONFIG_LIBDIR=:/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/usr/share/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/opt/vc/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR=/opt/software/raspberrypi/rpi-cross/rootfs
pkg-config =
Wed 8 Aug 06:33:55 BST 2018 pkg-config-wrapper.sh --static
--libs-only-other harfbuzz
PKG_CONFIG_DIR=
PKG_CONFIG_LIBDIR=:/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/usr/share/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/opt/vc/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR=/opt/software/raspberrypi/rpi-cross/rootfs
pkg-config = -pthread
就我所见,pkg-config被正确调用以进行交叉编译,所以现在我感到困惑,不知道下一步该怎么做。
我按如下方式调用CMake:
cmake \
-D RPI_ROOTFS=${RPI_ROOTFS} \
-D BUILD_TESTS=NO \
-D BUILD_PERF_TESTS=NO \
-D BUILD_PYTHON_SUPPORT=ON \
-D OPENCV_EXTRA_MODULES_PATH=${RPI_CROSS_HOME}/src/opencv_contrib-3.3.1/modules \
-D CMAKE_TOOLCHAIN_FILE=${RPI_CROSS_HOME}/src/opencv-3.3.1/platforms/linux/arm.toolchain.cmake \
${RPI_CROSS_HOME}/src/opencv-3.3.1
对OpenCV Cmake文件的大多数更改都是在opencv-3.3.1/cmake/OpenCVMinDepVersions.cmake
中进行的,如https://github.com/HesselM/rpicross_notes中所述
set(MIN_VER_CMAKE 2.8.12.2)
set(MIN_VER_CUDA 6.5)
set(MIN_VER_PYTHON2 2.6)
set(MIN_VER_PYTHON3 3.2)
set(MIN_VER_ZLIB 1.2.3)
set(MIN_VER_GTK 2.18.0)
# install dir
set( CMAKE_INSTALL_PREFIX ${RPI_ROOTFS}/usr/local CACHE STRING "")
set( CMAKE_FIND_ROOT_PATH "${RPI_ROOTFS}" CACHE FILEPATH "")
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
# compilers
set( CMAKE_C_COMPILER "/opt/cross/x-tools/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-gcc" CACHE FILEPATH "")
set( CMAKE_CXX_COMPILER "/opt/cross/x-tools/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-g++" CACHE FILEPATH "")
set( CMAKE_AR "/opt/cross/x-tools/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-ar" CACHE FILEPATH "")
set( CMAKE_RANLIB "/opt/cross/x-tools/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-ranlib" CACHE FILEPATH "")
#Pkg-config settings
set( RPI_PKGCONFIG_LIBDIR "${RPI_PKGCONFIG_LIBDIR}:${RPI_ROOTFS}/usr/lib/arm-linux-gnueabihf/pkgconfig" )
set( RPI_PKGCONFIG_LIBDIR "${RPI_PKGCONFIG_LIBDIR}:${RPI_ROOTFS}/usr/share/pkgconfig" )
set( RPI_PKGCONFIG_LIBDIR "${RPI_PKGCONFIG_LIBDIR}:${RPI_ROOTFS}/opt/vc/lib/pkgconfig" )
#set( PKG_CONFIG_EXECUTABLE "/usr/bin/pkg-config" CACHE FILEPATH "")
set( PKG_CONFIG_EXECUTABLE "/opt/cross/pkg-config-wrapper.sh" CACHE FILEPATH "")
set( ENV{PKG_CONFIG_DIR} "" CACHE FILEPATH "")
set( ENV{PKG_CONFIG_LIBDIR} "${RPI_PKGCONFIG_LIBDIR}" CACHE FILEPATH "")
set( ENV{PKG_CONFIG_SYSROOT_DIR} "${RPI_ROOTFS}" CACHE FILEPATH "")
# setup rpi (target) directories for compiler
set( RPI_INCLUDE_DIR "${RPI_INCLUDE_DIR} -isystem ${RPI_ROOTFS}/usr/include/arm-linux-gnueabihf")
set( RPI_INCLUDE_DIR "${RPI_INCLUDE_DIR} -isystem ${RPI_ROOTFS}/usr/include")
set( RPI_INCLUDE_DIR "${RPI_INCLUDE_DIR} -isystem ${RPI_ROOTFS}/usr/local/include")
set( RPI_LIBRARY_DIR "${RPI_LIBRARY_DIR} -Wl,-rpath ${RPI_ROOTFS}/usr/lib/arm-linux-gnueabihf")
set( RPI_LIBRARY_DIR "${RPI_LIBRARY_DIR} -Wl,-rpath ${RPI_ROOTFS}/lib/arm-linux-gnueabihf")
# Setup C/CXX flags.
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${RPI_INCLUDE_DIR}" CACHE STRING "" FORCE)
set( CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} ${RPI_INCLUDE_DIR}" CACHE STRING "" FORCE)
set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${RPI_LIBRARY_DIR}" CACHE STRING "" FORCE)
#Python2.7
set( PYTHON_EXECUTABLE /usr/bin/python2.7 CACHE STRING "")
set( PYTHON_LIBRARY_DEBUG "${RPI_ROOTFS}/usr/lib/arm-linux-gnueabihf/libpython2.7.so" CACHE STRING "")
set( PYTHON_LIBRARY_RELEASE "${RPI_ROOTFS}/usr/lib/arm-linux-gnueabihf/libpython2.7.so" CACHE STRING "")
set( PYTHON_LIBRARY "${RPI_ROOTFS}/usr/lib/arm-linux-gnueabihf/libpython2.7.so" CACHE STRING "")
set( PYTHON_INCLUDE_DIR "${RPI_ROOTFS}/usr/include/python2.7" CACHE STRING "")
set( PYTHON2_NUMPY_INCLUDE_DIRS "${RPI_ROOTFS}/usr/lib/python2.7/dist-packages/numpy/core/include" CACHE STRING "")
set( PYTHON2_PACKAGES_PATH "${RPI_ROOTFS}/usr/local/lib/python2.7/site-packages" CACHE STRING "")
我还根据https://github.com/HesselM/rpicross_notes更改了opencv-3.3.1/platforms/linux/arm.toolchain.cmake
,将"-mthumb“替换为"-marm”,以提供以下内容
if(COMMAND toolchain_save_config)
return() # prevent recursive call
endif()
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
set(CMAKE_SYSTEM_PROCESSOR arm)
else()
#message("CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/gnu.toolchain.cmake")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm AND NOT ARM_IGNORE_FP)
set(FLOAT_ABI_SUFFIX "")
if(NOT SOFTFP)
set(FLOAT_ABI_SUFFIX "hf")
endif()
endif()
if(NOT "x${GCC_COMPILER_VERSION}" STREQUAL "x")
set(__GCC_VER_SUFFIX "-${GCC_COMPILER_VERSION}")
endif()
if(NOT DEFINED CMAKE_C_COMPILER)
find_program(CMAKE_C_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-gcc${__GCC_VER_SUFFIX})
else()
#message(WARNING "CMAKE_C_COMPILER=${CMAKE_C_COMPILER} is defined")
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER)
find_program(CMAKE_CXX_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-g++${__GCC_VER_SUFFIX})
else()
#message(WARNING "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} is defined")
endif()
if(NOT DEFINED CMAKE_LINKER)
find_program(CMAKE_LINKER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld)
else()
#message(WARNING "CMAKE_LINKER=${CMAKE_LINKER} is defined")
endif()
if(NOT DEFINED CMAKE_AR)
find_program(CMAKE_AR NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar)
else()
#message(WARNING "CMAKE_AR=${CMAKE_AR} is defined")
endif()
if(NOT DEFINED ARM_LINUX_SYSROOT AND DEFINED GNU_MACHINE)
set(ARM_LINUX_SYSROOT /usr/${GNU_MACHINE}${FLOAT_ABI_SUFFIX})
endif()
if(NOT DEFINED CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "" CACHE INTERAL "")
set(CMAKE_C_FLAGS "" CACHE INTERAL "")
set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERAL "")
set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERAL "")
set(CMAKE_EXE_LINKER_FLAGS "" CACHE INTERAL "")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
set(CMAKE_CXX_FLAGS "-marm ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-marm ${CMAKE_C_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,nocopyreloc")
endif()
if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
set(ARM_LINKER_FLAGS "-Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
set(ARM_LINKER_FLAGS "-Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
endif()
set(CMAKE_SHARED_LINKER_FLAGS "${ARM_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${ARM_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${ARM_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
else()
#message(WARNING "CMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}' is defined")
endif()
if(USE_NEON)
message(WARNING "You use obsolete variable USE_NEON to enable NEON instruction set. Use -DENABLE_NEON=ON instead." )
set(ENABLE_NEON TRUE)
elseif(USE_VFPV3)
message(WARNING "You use obsolete variable USE_VFPV3 to enable VFPV3 instruction set. Use -DENABLE_VFPV3=ON instead." )
set(ENABLE_VFPV3 TRUE)
endif()
set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${ARM_LINUX_SYSROOT})
if(EXISTS ${CUDA_TOOLKIT_ROOT_DIR})
set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CUDA_TOOLKIT_ROOT_DIR})
endif()
set(TOOLCHAIN_CONFIG_VARS ${TOOLCHAIN_CONFIG_VARS}
ARM_LINUX_SYSROOT
ENABLE_NEON
ENABLE_VFPV3
CUDA_TOOLKIT_ROOT_DIR
)
toolchain_save_config()
这是CMake的输出:
-- General configuration for OpenCV 3.3.1 =====================================
-- Version control: unknown
--
-- Extra modules:
-- Location (extra): /opt/software/raspberrypi/rpi-cross/src/opencv_contrib-3.3.1/modules
-- Version control (extra): unknown
--
-- Platform:
-- Timestamp: 2018-08-08T05:33:57Z
-- Host: Linux 4.15.0-29-generic x86_64
-- Target: Linux 1 arm
-- CMake: 3.5.1
-- CMake generator: Unix Makefiles
-- CMake build tool: /usr/bin/make
-- Configuration: Release
--
-- CPU/HW features:
-- Baseline:
-- requested: DETECT
-- disabled: VFPV3 NEON
--
-- C/C++:
-- Built as dynamic libs?: YES
-- C++11: YES
-- C++ Compiler: /opt/cross/x-tools/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-g++ (ver 6.3.0)
-- C++ flags (Release): -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include/arm-linux-gnueabihf -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/local/include -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
-- C++ flags (Debug): -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include/arm-linux-gnueabihf -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/local/include -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
-- C Compiler: /opt/cross/x-tools/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-gcc
-- C flags (Release): -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include/arm-linux-gnueabihf -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/local/include -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include/arm-linux-gnueabihf -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/local/include -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -mfp16-format=ieee -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
-- C flags (Debug): -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include/arm-linux-gnueabihf -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/local/include -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include/arm-linux-gnueabihf -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/include -isystem /opt/software/raspberrypi/rpi-cross/rootfs/usr/local/include -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -mfp16-format=ieee -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
-- Linker flags (Release):
-- Linker flags (Debug):
-- ccache: NO
-- Precompiled headers: NO
-- Extra dependencies: dl m pthread rt
-- 3rdparty dependencies:
--
-- OpenCV modules:
-- To be built: core flann imgproc ml objdetect phase_unwrapping photo plot reg surface_matching video xphoto bgsegm dnn face freetype fuzzy img_hash imgcodecs shape videoio xobjdetect highgui superres bioinspired dpm features2d line_descriptor saliency text calib3d ccalib datasets rgbd stereo structured_light tracking videostab xfeatures2d ximgproc aruco optflow stitching python2
-- Disabled: js world contrib_world
-- Disabled by dependency: -
-- Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java python3 ts viz cnn_3dobj cvv dnn_modern hdf matlab sfm
--
-- GUI:
-- QT: NO
-- GTK+ 3.x: YES (ver 3.22.11)
-- GThread : YES (ver 2.50.3)
-- GtkGlExt: NO
-- OpenGL support: NO
-- VTK support: NO
--
-- Media I/O:
-- ZLib: zlib (ver 1.2.8)
-- JPEG: libjpeg (ver 90)
-- WEBP: build (ver encoder: 0x020e)
-- PNG: build (ver 1.6.24)
-- TIFF: build (ver 42 - 4.0.2)
-- JPEG 2000: build (ver 1.900.1)
-- OpenEXR: build (ver 1.7.1)
-- GDAL: NO
-- GDCM: NO
--
-- Video I/O:
-- DC1394 1.x: NO
-- DC1394 2.x: YES (ver 2.2.5)
-- FFMPEG: NO
-- avcodec: YES (ver 57.64.101)
-- avformat: YES (ver 57.56.101)
-- avutil: YES (ver 55.34.101)
-- swscale: YES (ver 4.2.100)
-- avresample: YES (ver )
-- GStreamer:
-- base: YES (ver )
-- video: YES (ver )
-- app: YES (ver )
-- riff: YES (ver )
-- pbutils: YES (ver )
-- OpenNI: NO
-- OpenNI PrimeSensor Modules: NO
-- OpenNI2: NO
-- PvAPI: NO
-- GigEVisionSDK: NO
-- Aravis SDK: NO
-- UniCap: NO
-- UniCap ucil: NO
-- V4L/V4L2: NO/YES
-- XIMEA: NO
-- Xine: NO
-- Intel Media SDK: NO
-- gPhoto2: YES
--
-- Parallel framework: pthreads
--
-- Trace: YES ()
--
-- Other third-party libraries:
-- Use Intel IPP: NO
-- Use Intel IPP IW: NO
-- Use VA: NO
-- Use Intel VA-API/OpenCL: NO
-- Use Lapack: NO
-- Use Eigen: NO
-- Use Cuda: NO
-- Use OpenCL: YES
-- Use OpenVX: NO
-- Use custom HAL: YES (carotene (ver 0.0.1))
--
-- OpenCL: <Dynamic loading of OpenCL library>
-- Include path: /opt/software/raspberrypi/rpi-cross/src/opencv-3.3.1/3rdparty/include/opencl/1.2
-- Use AMDFFT: NO
-- Use AMDBLAS: NO
--
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 2.7.12)
-- Libraries: /opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/libpython2.7.so (ver 2.7.13)
-- numpy: /opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/python2.7/dist-packages/numpy/core/include (ver undefined - cannot be probed because of the cross-compilation)
-- packages path: /opt/software/raspberrypi/rpi-cross/rootfs/usr/local/lib/python2.7/site-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3 (ver 3.5.2)
--
-- Python (for build): /usr/bin/python2.7
--
-- Java:
-- ant: /opt/software/packages/java/apache-ant-1.9.6/bin/ant (ver 1.9.6)
-- JNI: NO
-- Java wrappers: NO
-- Java tests: NO
--
-- Matlab: Matlab not found or implicitly disabled
--
-- Documentation:
-- Doxygen: NO
--
-- Tests and samples:
-- Tests: NO
-- Performance tests: NO
-- C/C++ Examples: NO
--
-- Install path: /opt/software/raspberrypi/rpi-cross/rootfs/usr/local
--
-- cvconfig.h is in: /opt/software/raspberrypi/rpi-cross/build/opencv
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/software/raspberrypi/rpi-cross/build/opencv
在这一点上,我不知所措,不知道下一步该怎么做。可能的问题是什么?
发布于 2018-08-13 02:50:52
我遇到了完全相同的问题。对我来说,解决方案是将libfreetype.a
和libharfbuzz.a
复制到/home/alfred/Development/raspi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/libc/usr/lib/arm-linux-gnueabihf/
目录。
这是启动编译器和链接器的子目录(64位,因为我的ubuntu是64位系统)。
我认为这只是一个肮脏的变通方法,但我不知道如何修复cmake系统。如果你找到了更好的解决方案,请告诉我。
https://stackoverflow.com/questions/51744641
复制相似问题