C++ 在Ubuntu上为Raspberry Pi交叉编译opencv项目
我已经为此挣扎了两天,但都没能成功 到目前为止我所做的:C++ 在Ubuntu上为Raspberry Pi交叉编译opencv项目,c++,opencv,ubuntu,raspberry-pi,cross-compiling,C++,Opencv,Ubuntu,Raspberry Pi,Cross Compiling,我已经为此挣扎了两天,但都没能成功 到目前为止我所做的: 在Ubuntu 12.04 LTS上从源代码构建opencv 2.4.8 -->OpenCV项目在ubuntu上编译和运行 在Raspberry Pi Raspian上从源代码构建opencv 2.4.8 -->OpenCV项目在Raspberry Pi上编译和运行 使用crosstools ng()为Raspberry Pi构建交叉编译器 -->在Ubuntu上用交叉编译程序在树莓Pi上运行的C++程序 我的问题是什么: Ope
- 在Ubuntu 12.04 LTS上从源代码构建opencv 2.4.8 -->OpenCV项目在ubuntu上编译和运行
- 在Raspberry Pi Raspian上从源代码构建opencv 2.4.8 -->OpenCV项目在Raspberry Pi上编译和运行
- 使用crosstools ng()为Raspberry Pi构建交叉编译器 -->在Ubuntu上用交叉编译程序在树莓Pi 上运行的C++程序
我的问题是什么:
|2|fatal error: opencv2/highgui/highgui.hpp: No such file or directory|
# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
# specify the cross compiler
SET(CMAKE_C_COMPILER
/home/christian/Programming/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER
/home/christian/Programming/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-g++)
# where is the target environment
SET(CMAKE_FIND_ROOT_PATH
/home/christian/Programming/x-tools/arm-unknown-linux-gnueabi)
# 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)
使用此工具链,我尝试使用以下命令交叉编译OpenCV:
cmake -DCMAKE_TOOLCHAIN_FILE=../Toolchain-RaspberryPi.cmake ../
执行make命令后,它将编译到27%。在这里,它停止与这个错误
[ 27%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.cpp.o
In file included from /home/christian/Downloads/opencv-2.4.8/modules/highgui/src/cap_ffmpeg_impl.hpp:60:0,
from /home/christian/Downloads/opencv-2.4.8/modules/highgui/src/cap_ffmpeg.cpp:45:
/home/christian/Downloads/opencv-2.4.8/modules/highgui/src/ffmpeg_codecs.hpp:81:36: fatal error: libavformat/avformat.h: No such file or directory
#include <libavformat/avformat.h>
^
compilation terminated.
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.cpp.o] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
所以我的问题是: 如何让ubuntu上的交叉编译器与opencv一起工作?我只想在ubuntu上编译,在Pi上复制程序并在那里运行 非常感谢您可以通过以下链接将Qt(c++)与OpenCV交叉编译到raspberry pi:
这个链接应该为您提供关于如何使您的系统能够交叉编译raspberry pi的所有必要信息。当你建立了链接的方式,我想如果你喜欢,你也可以使用OpenCV库来交叉编译C++而不需要Qt。p> 我意识到这是一个老问题,但作为记录,我能够从Ubuntu交叉编译我的OpenCV项目 在我的例子中,我使用了github上预先构建的raspberry pi工具链:Ubuntu12.0.4。我采取的方法是将本地库(安装了OpenCV和PiCamera库)从目标Raspberry Pi系统复制到Ubuntu实例,并使用CMAKE_工具链_文件支持,就像你在文章中提到的那样 然而,我必须克服一些问题,我在这篇文章中谈到了这些问题: 重点是:
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
SET(DEVROOT $ENV{HOME}/pidev)
SET(PIROOT ${DEVROOT}/piroot)
SET(PITOOLS ${DEVROOT}/pitools)
SET(TOOLROOT ${PITOOLS}/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64)
# specify the cross compiler
SET(CMAKE_C_COMPILER ${TOOLROOT}/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLROOT}/bin/arm-linux-gnueabihf-g++)
SET(FLAGS "-Wl,-rpath-link,${PIROOT}/opt/vc/lib -Wl,-rpath-link,${PIROOT}/lib/arm-linux-gnueabihf -Wl,-rpath-link,${PIROOT}/usr/lib/arm-linux-gnueabihf -Wl,-rpath-link,${PIROOT}/usr/local/lib")
UNSET(CMAKE_C_FLAGS CACHE)
UNSET(CMAKE_CXX_FLAGS CACHE)
SET(CMAKE_CXX_FLAGS ${FLAGS} CACHE STRING "" FORCE)
SET(CMAKE_C_FLAGS ${FLAGS} CACHE STRING "" FORCE)
SET(CMAKE_SYSROOT ${PIROOT})
SET(CMAKE_FIND_ROOT_PATH ${PIROOT})
# 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)
其中,我的主目录中有一个pidev文件夹,在该文件夹下,piroot有一个来自我的pi主机的/usr/opt/etc和/lib副本,pitools是我上面引用的GitHub的工具链的克隆
我的项目的CMakeLists.txt文件是:
cmake_minimum_required(VERSION 2.8)
project( PiCamCVTest )
SET(COMPILE_DEFINITIONS -Werror)
include_directories(SYSTEM ${PIROOT}/opt/vc/include ${PIROOT}/opt/vc/include/interface/vcos/pthreads ${PIROOT}/opt/vc/include/interface/vmcs_host/linux )
link_directories( ${PIROOT}/opt/vc/lib )
add_executable(PiCamCVTest main.cpp camera.cpp cameracontrol.cpp graphics.cpp)
target_link_libraries(PiCamCVTest libmmal_core.so libmmal_util.so libmmal_vc_client.so libvcos.so librt.so libbcm_host.so GLESv2 EGL libopencv_core.so libopencv_imgproc.so)
希望这能有所帮助。您从pi哪里获得opencv库的副本?我在pi上运行了
sudo apt get install libopencv dev
,并成功安装。但是我找不到任何libopencv*。所以,在/usr/lib
,/lib
,/usr/local/lib
中也找不到。我只在/usr/include/opencv
和/usr/include/opencv2
中找到头文件。但是,我非常确定我可以使用opencv在pi上进行本地编译,只是找不到LIB在哪里。
cmake_minimum_required(VERSION 2.8)
project( PiCamCVTest )
SET(COMPILE_DEFINITIONS -Werror)
include_directories(SYSTEM ${PIROOT}/opt/vc/include ${PIROOT}/opt/vc/include/interface/vcos/pthreads ${PIROOT}/opt/vc/include/interface/vmcs_host/linux )
link_directories( ${PIROOT}/opt/vc/lib )
add_executable(PiCamCVTest main.cpp camera.cpp cameracontrol.cpp graphics.cpp)
target_link_libraries(PiCamCVTest libmmal_core.so libmmal_util.so libmmal_vc_client.so libvcos.so librt.so libbcm_host.so GLESv2 EGL libopencv_core.so libopencv_imgproc.so)