1. 程式人生 > >[置頂] 樹莓派&qt5交叉編譯

[置頂] 樹莓派&qt5交叉編譯

  • 樹莓派上安裝qt5 
    • 要求安裝的系統是jessie
    • 安裝qt&qtcreator 

      sudo apt-get install qt-default//目前是qt5.3.2 
      sudo apt-get install qtcreator//安裝完這一步,qt程式的介面才啟動起來 
    • 編譯

      • 掛載樹莓派(百度jessie掛載即可//交叉編譯時會使用樹莓派的庫和工具,以後qtcreator程式時,也會用到系統中的檔案)

         sudo mkdir /mnt/rasp-pi-rootfs
        sudo mount -o loop,offset=62914560 2015-05-05-raspbian-wheezy.img /mnt/rasp-pi
        -rootfs
        • 1
        • 2
        • 1
        • 2
      • 矯正系統連結和庫路徑(是用的是掛載的樹莓派檔案;檔案位置~/opt,如果更改,請對應)

        cd ~/opt/cross-compile-tools
        sudo ./fixQualifiedLibraryPaths /mnt/rasp-pi-rootfs/ ~/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-gcc
        • 1
        • 2
        • 1
        • 2
      • 配置make

        cd ~/opt/cross-compile-tools
        sudo ./fixQualifiedLibraryPaths /mnt/rasp-pi-rootfs/ ~/opt/gcc-4.7-linaro-rpi
        -gnueabihf/bin/arm-linux-gnueabihf-gcc
        • 1
        • 2
        • 1
        • 2
      • make&install

        make -j 4  //這步會發生符號連結問題,見下
        sudo make install  //安裝到掛載的樹莓派系統中。
        • 1
        • 2
        • 1
        • 2
      • 燒製映象到SD卡(現在不使用該步驟,直接在樹莓派上以apt-get方式安裝qt-default和qtcreator) 
        最終,我們將掛載的映象燒到sd卡,啟動系統後,就可以直接使用qt5了。所以編譯的qt5的庫就在掛載的映象中,我們只需把它拷到樹莓派上,再設定環境變數,就應該能用了。qt5庫位置:/mnt/rasp-pi-rootfs/usr/local/qt5pi
    • 注意事項

      • 交叉編譯前最好不要使用過QT,或者重啟機器後交叉編譯,不要啟動qtcreator等
      • 如果不按照官方教程的檔案結構,請將檔案結構對應準確
      • 關於安裝32庫 
         sudo apt-get install ia32-libs
         //如果無法定位ia32-libs嘗試安裝下列內容,或者安裝時提示的軟體 lib32z1 lib32ncurses5 lib32bz2-1.0 
        • 1
        • 2
        • 1
        • 2
  • 遇到的問題及解決方案

    • make階段的符號連結問題 
      按照官方教程正確操作後,出現undefined reference to `__dlopen’等問題,顯示內容如下


      qlibrary_unix.cpp:(.text+0x1330): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking 
      /mnt/rasp-pi-rootfs/usr/lib/arm-Linux-gnueabihf/libdl.a(dlopen.o): In function `dlopen': 
      (.text+0xc): undefined reference to `__dlopen' 
      /mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf/libdl.a(dlclose.o): In function `dlclose': 
      (.text+0x0): undefined reference to `__dlclose' 
      /mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf/libdl.a(dlsym.o): In function `dlsym': 
      (.text+0xc): undefined reference to `__dlsym' 
      /mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf/libdl.a(dlerror.o): In function `dlerror': 
      (.text+0x0): undefined reference to `__dlerror' 
      /mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf/libm.a(feholdexcpt.o): In function `feholdexcept': 
      (.text+0x48): undefined reference to `_dl_hwcap' 
      /mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf/libm.a(fesetenv.o): In function `fesetenv': 
      (.text+0x64): undefined reference to `_dl_hwcap' 
      collect2: error: ld returned 1 exit status 
      Makefile:1215: recipe for target '../../lib/libQt5Core.so.5.5.1' failed 
      make[2]: *** [../../lib/libQt5Core.so.5.5.1] Error 1 
      make[2]: Leaving directory '/home/liu/bin/opt/qt5/qtbase/src/corelib' 
      Makefile:170: recipe for target 'sub-corelib-make_first' failed 
      make[1]: *** [sub-corelib-make_first] Error 2 
      make[1]: Leaving directory '/home/liu/bin/opt/qt5/qtbase/src' 
      Makefile:45: recipe for target 'sub-src-make_first' failed 
      make: *** [sub-src-make_first] Error 2 

      解決方案 
      軟連線不對,重建兩個軟連線,均在掛載的樹莓派映象上。如果已經存在該軟連結,先刪除再建立。

      //最終,我們將掛載的映象燒到sd卡,啟動系統後,就可以直接使用qt5了,所以編譯的qt5的庫就在掛載的映象中,我們只需把它拷到樹莓派上,再設定環境變數,就應該能用了。
      sudo ln -s /mnt/rasp-pi-rootfs/lib/arm-linux-gnueabihf/libdl-2.13.so /mnt/rasp-pi-rootfs/lib/arm-linux-gnueabihf/libdl.so
      sudo ln -s  /mnt/rasp-pi-rootfs/lib/arm-linux-gnueabihf/libm-2.13.so  /mnt/rasp-pi-rootfs/usr/lib/arm-linux-gnueabihf/libm.so
      • 1
      • 2
      • 3
      • 1
      • 2
      • 3
      出現上述問題的原因
      

      in that case the fixQualifiedLibraryPaths won’t help you as it can’t find the symlinks. Copying libdl.so and libm.so might also fail, for example, if you use a flash drive to copy data from your existing Raspberry Pi, it won’t copy them as symlinks, but will copy the libraries themselves. However, for the build to succeed, it seems to require symlinks.

    • 沒有找到檔案問題 
      在make 時發生如下問題

      /vc/lib -L/home/liu/bin/opt/qt5/qtlocation/lib -lQt5Location -L/home/liu/bin/opt/qt5/qtbase/lib -L/home/liu/bin/opt/qt5/qtdeclarative/lib -lQt5Quick -lQt5Gui -lQt5Qml -lQt5Network -lQt5Positioning -lQt5Core -lGLESv2 -lpthread -lpoly2tri 
      /home/liu/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lpoly2tri
      collect2: error: ld returned 1 exit status
      Makefile:281: recipe for target '../../../qml/QtLocation/libdeclarative_location.so' failed
      make[4]: *** [../../../qml/QtLocation/libdeclarative_location.so] Error 1
      make[4]: Leaving directory '/home/liu/bin/opt/qt5/qtlocation/src/imports/location'
      Makefile:80: recipe for target 'sub-location-install_subtargets' failed
      make[3]: *** [sub-location-install_subtargets] Error 2
      make[3]: Leaving directory '/home/liu/bin/opt/qt5/qtlocation/src/imports'
      Makefile:135: recipe for target 'sub-imports-install_subtargets' failed
      make[2]: *** [sub-imports-install_subtargets] Error 2
      make[2]: Leaving directory '/home/liu/bin/opt/qt5/qtlocation/src'
      Makefile:56: recipe for target 'sub-src-install_subtargets' failed
      make[1]: *** [sub-src-install_subtargets] Error 2
      make[1]: Leaving directory '/home/liu/bin/opt/qt5/qtlocation'
      Makefile:366: recipe for target 'module-qtlocation-install_subtargets' failed
      make: *** [module-qtlocation-install_subtargets] Error 2
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17

      解決辦法其原因可能是,make配置檔案和原始檔不匹配造成的,請重新獲取原始碼,重新編譯。

    • 啟動不出來qt介面問題 
      問題描述:在終端啟動程式後,測試字元都已經顯示,但圖形渲染沒有出現。因為這個為題讓我,真正工作了三天!!

      解決方案 
      樹莓派上安裝qt-default其版本是5.3.2,交叉編譯時請編譯對應版本。安裝qtcreator,再啟動測試demo時圖形介面就渲染出來了。

    • 樹莓派上啟動qt程式發現不了裝置等,百度即可