2014-03-07 154 views
5

我正在爲此苦苦掙扎2天,並且沒有得到它的工作。在Ubuntu上針對Raspberry Pi交叉編譯opencv項目

我到目前爲止已經完成:從源在Ubuntu 12.04


我有什麼問題的方案:

  • OpenCV程序不會與交叉編譯器編譯
  • |2|fatal error: opencv2/highgui/highgui.hpp: No such file or directory| 
    

  • 我想我需要在Ubuntu上交叉編譯OpenCV。從我的交叉編譯器我也有一個工具鏈
  • # 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 ../ 
    

    它編譯直到27%make命令後。在那裏,它停止與此錯誤

    [ 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 
    

  • 我試圖在樹莓派編譯OpenCV的頭文件和庫複製到我的Ubuntu電腦,將它們鏈接。我得到的錯誤的負載,同時編制
  • ||=== RPi_Cross_CV, Debug ===| 
    ||warning: libz.so.1, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_core.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libjpeg.so.8, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libpng12.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libtiff.so.4, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libjasper.so.1, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libgtk-x11-2.0.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libgdk-x11-2.0.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libatk-1.0.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libgio-2.0.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libpangoft2-1.0.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libpangocairo-1.0.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libgdk_pixbuf-2.0.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libcairo.so.2, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libpango-1.0.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libfreetype.so.6, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libfontconfig.so.1, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libgobject-2.0.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libglib-2.0.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libgthread-2.0.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libgstbase-0.10.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libgstreamer-0.10.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libgmodule-2.0.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libxml2.so.2, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libdc1394.so.22, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libv4l1.so.0, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libavcodec.so.53, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libavformat.so.53, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libavutil.so.51, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ||warning: libswscale.so.2, needed by ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8, not found (try using -rpath or -rpath-link)| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_3.9'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_0'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `g_time_val_add'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `jas_image_writecmpt'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `gtk_widget_queue_draw'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_53'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_51'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_8.0'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `jas_cmprof_destroy'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_0'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `g_return_if_fail_warning'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `dc1394_camera_enumerate'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `dc1394_capture_stop'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `compress'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `dc1394_get_image_size_from_video_mode'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `g_timeout_add'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_0'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `v4l2_munmap'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `dc1394_feature_whitebalance_get_value'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `gtk_type_new'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `jas_image_destroy'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_53'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_2'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_core.so.2.4.8||undefined reference to `gzeof'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `gtk_style_attach'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `gtk_widget_get_type'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `gtk_window_resize'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `g_cond_broadcast'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `dc1394_video_get_supported_framerates'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_8.0'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_53'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_3.9'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `uncompress'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `g_type_check_instance_cast'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `g_usleep'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_53'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `g_get_current_time'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_8.0'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `dc1394_video_get_mode'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_8.0'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_53'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `gtk_window_set_geometry_hints'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `gtk_signal_connect_full'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `gdk_draw_rgb_image'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `gtk_widget_queue_resize'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `dc1394_video_set_mode'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `jas_stream_close'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `[email protected]_8.0'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `jas_image_readcmpt'| 
    ../../../../Programming/x-tools/usr-local/lib/libopencv_highgui.so.2.4.8||undefined reference to `gtk_disable_setlocale'| 
    ||More errors follow but not being shown.| 
    ||Edit the max errors limit in compiler options...| 
    ||=== Build finished: 50 errors, 29 warnings ===| 
    

    所以我的問題是:

    我怎樣才能在Ubuntu一個交叉編譯器與OpenCV的工作?我只想在ubuntu上編譯,在Pi上覆製程序並在那裏運行。

    非常感謝

    回答

    5

    我意識到這是一個老問題,但爲了記錄,我能夠從Ubuntu交叉編譯我的OpenCV項目。

    在我的情況下,我在github上使用了預構建的覆盆子pi工具鏈:在Ubuntu 12.0.4上使用https://github.com/raspberrypi/tools。我採取了將目標Raspberry Pi系統中的本地庫(安裝了OpenCV和PiCamera庫)複製到Ubuntu實例並使用CMAKE_TOOLCHAIN_FILE支持的方法,就像您在文章中提到的一樣。

    然而,有一定的問題,我必須克服,這是我在這個崗位包括:https://solderspot.wordpress.com/2016/02/04/cross-compiling-for-raspberry-pi-part-ii

    的關鍵點是:

    1. CMAKE_FIND_ROOT_PATH沒有影響。我不得不使用CMAKE_SYSROOT。

    2. 在我的CMakeLists.txt文件中,我仍然必須明確地將所有路徑與通過本機文件系統複製到的文件夾路徑相加。

    3. 我還需要明確指定CMAKE_TOOLCHAIN_FILE中的動態庫鏈接路徑,因爲工具鏈沒有正確解析/usr/etc/ld.so.conf文件。

    目前唯一的問題我還沒能解決與Raspbian的傑西釋放做,爲的OpenCV採用的GCC/G ++ 4.9功能,它不是由GCC/G ++ 4.8版本的工具鏈支持。看起來工具鏈將在不久的將來得到增強以支持4.9。

    我的最後CMAKE_TOOLCHAIN_FILE是:

    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) 
    

    在哪裏我在我的主目錄,並根據該pirootpidev文件夾必須在/ usr /選擇/ etc和/ lib中的副本從我的PI主機和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) 
    

    希望這有助於。

    +0

    你從哪裏取得pi的opencv庫的副本?我在我的pi上運行'sudo apt-get install libopencv-dev'併成功安裝。但是我在'/ usr/lib','/ lib','/ usr/local/lib'中找不到任何libopencv * .so。我只能在'/ usr/include/opencv'和'/ usr/include/opencv2'中找到頭文件。但是,我非常肯定,我可以使用opencv在pi上本地編譯,只是無法找到libs的位置。 – Alston

    -1

    我按照上面的步驟,我得到foolowing錯誤:

    make[2]: *** No rule to make target '/opt/vc/lib/libmmal_core.so', needed by 'agv_car'. Stop. 
    

    有沒有人成功地跨越編譯使用了OpenCV和raspicam庫項目?

    +0

    請在評論部分發表您的反饋,而不是回答。 – Emadpres