为树莓派 pi3 交叉编译 Qt 时出错

Posted

技术标签:

【中文标题】为树莓派 pi3 交叉编译 Qt 时出错【英文标题】:Error while cross compiling Qt for a raspberry pi3 【发布时间】:2017-10-09 20:52:12 【问题描述】:

我想交叉编译 Qt 为树莓派开发一个 gui。我一直在关注这个教程:https://wiki.qt.io/RaspberryPi2EGLFS

我正在使用这个配置命令:

./configure -release -opengl es2 -device linux-rasp-pi3-g++ -device-option \
CROSS_COMPILE=~/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf- \
-sysroot ~/raspi/sysroot -opensource -confirm-license \
-make libs -no-use-gold-linker -prefix /usr/local/qt5pi \
-extprefix ~/raspi/qt5pi -hostprefix ~/raspi/qt5 -v

这是我要返回的错误:

/home/vbox/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++ -mfloat-abi=hard --sysroot=/home/vbox/raspi/sysroot -Wl,-O1 -Wl,-rpath-link,/home/vbox/raspi/sysroot/opt/vc/lib -Wl,-rpath-link,/home/vbox/raspi/sysroot/usr/lib/arm-linux-gnueabihf -Wl,-rpath-link,/home/vbox/raspi/sysroot/lib/arm-linux-gnueabihf -o verifyspec verifyspec.o    
/home/vbox/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find crt1.o: No such file or directory
/home/vbox/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find crti.o: No such file or directory
/home/vbox/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lm
 collect2: error: ld returned 1 exit status
 Makefile:66: recipe for target 'verifyspec' failed
 make: *** [verifyspec] Error 1
Note: Also available for Linux: linux-clang linux-icc
ERROR: Cannot compile a minimal program. The toolchain or QMakeSpec is broken.`

这是 config.log:

vbox@vbox:~/qtbase$ cat config.log
Command line: -release -opengl es2 -device linux-rasp-pi3-g++ -device-option CROSS_COMPILE=/home/vbox/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf- -sysroot /home/vbox/raspi/sysroot -opensource -confirm-license -make libs -no-use-gold-linker -prefix /usr/local/qt5pi -extprefix /home/vbox/raspi/qt5pi -hostprefix /home/vbox/raspi/qt5 -v
executing config test machineTuple
+ /home/vbox/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++ -dumpmachine
 arm-linux-gnueabihf
test config.qtbase.tests.machineTuple succeeded
executing config test verifyspec
+ cd /home/vbox/qtbase/config.tests/verifyspec && /home/vbox/qtbase/bin/qmake "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_CFLAGS += --sysroot=/home/vbox/raspi/sysroot" "QMAKE_CXXFLAGS += --sysroot=/home/vbox/raspi/sysroot" "QMAKE_LFLAGS += --sysroot=/home/vbox/raspi/sysroot" -early "CONFIG += cross_compile" /home/vbox/qtbase/config.tests/verifyspec
 Info: creating stash file /home/vbox/qtbase/config.tests/.qmake.stash
+ cd /home/vbox/qtbase/config.tests/verifyspec && MAKEFLAGS= /usr/bin/make
 /home/vbox/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++ -c -march=armv8-a -mtune=cortex-a53 -mfpu=crypto-neon-fp-armv8 -mfloat-abi=hard --sysroot=/home/vbox/raspi/sysroot -O2 -std=gnu++11 -w -fPIC  -I. -I/home/vbox/qtbase/mkspecs/devices/linux-rasp-pi3-g++ -o verifyspec.o verifyspec.cpp
 /home/vbox/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++ -mfloat-abi=hard --sysroot=/home/vbox/raspi/sysroot -Wl,-O1 -Wl,-rpath-link,/home/vbox/raspi/sysroot/opt/vc/lib -Wl,-rpath-link,/home/vbox/raspi/sysroot/usr/lib/arm-linux-gnueabihf -Wl,-rpath-link,/home/vbox/raspi/sysroot/lib/arm-linux-gnueabihf -o verifyspec verifyspec.o    /home/vbox/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find crt1.o: No such file or directory
 /home/vbox/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find crti.o: No such file or directory
 /home/vbox/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lm
 collect2: error: ld returned 1 exit status
 Makefile:66: recipe for target 'verifyspec' failed
 make: *** [verifyspec] Error 1

我不知道从哪里开始,我没有足够的知识来开始调试这个问题。是否有可用的替代工具链?还是 QMakeSpec 的问题?任何有关尝试的建议都会非常有帮助。

【问题讨论】:

这是错误的重要部分:/bin/ld: cannot find -lm 这通常是未正确安装构建工具的结果。例如,在 Ubuntu 上,您可以通过安装 build-essential 来解决此问题。不过,我不确定您需要对 Raspberry Pi sysroot 做什么。尝试再次逐步完成教程,并确保您没有错过安装步骤。如果这不起作用,请搜索并查看其他人是否遇到过 ld 在 Raspberry Pi 上找不到 -lm 的问题。 【参考方案1】:

这篇博文似乎更针对 RPi3,而且可能也是如此(2017 年 1 月 12 日):

https://medium.com/@amirmann/how-to-cross-compile-qt-for-raspberry-pi-3-on-linux-ubuntu-for-beginners-75acf2a078c

sudo apt-get upgrade
sudo apt-get update
sudo apt-get install libgl1-mesa-dev
...
sudo apt-get build-dep qt5-default
sudo apt-get install libxcb-xinerama0-dev
sudo apt-add-repository ppa:u-szeged/sedkit
sudo apt-get update
sudo apt-get install sedkit-env-qtwebkit
sudo apt-get install build-essential perl python git
sudo apt-get install “^libxcb.*” libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev
sudo apt-get install flex bison gperf libicu-dev libxslt-dev ruby
sudo apt-get install libssl-dev libxcursor-dev libxcomposite-dev libxdamage-dev libxrandr-dev libfontconfig1-dev libcap-dev libxtst-dev libpulse-dev libudev-dev libpci-dev libnss3-dev libasound2-dev libxss-dev libegl1-mesa-dev gperf bison
sudo apt-get install libbz2-dev libgcrypt11-dev libdrm-dev libcups2-dev libatkmm-1.6-dev
sudo apt-get install libasound2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

在您正在查看的 wiki 上有一个注释,说明他们为使其在较新的版本上工作所做的一些事情。以下是该 wiki 页面的一些历史记录:

https://wiki.qt.io/index.php?title=RaspberryPi2EGLFS&type=revision&diff=31538&oldid=30634

然后是 Qt 的设备创建许可版本,然后您将使用以下说明:

http://doc.qt.io/QtForDeviceCreation/qtee-preparing-hardware-rasberrypi.html

在从 Scratch 深入研究有关 Linux 的文章时,我总能学到很多东西。在我最近构建的 Qt 中,它们非常有用。

http://www.linuxfromscratch.org/blfs/view/8.0/x/qt5.html

希望这些链接有所帮助。

【讨论】:

我开始使用您链接的第一个教程,但它在ERROR: The OpenGL functionality tests failed! 上失败了我能够通过在树莓派上安装 libgles2-mesa-dev 并使用 rsync 获取库来解决这个问题,即如果我刚刚在 Ubuntu 中安装,修复似乎没有帮助。【参考方案2】:

这是我为 raspberry-pi 交叉编译 Qt 的 bash 脚本。你可以 这个脚本带有命令<script name> <TcpIp of Raspberrry> $USER

#!/bin/bash
RASP_ADR=$1
USERNAME=$2
if [ ! $RASP_ADR ] 
then
        echo "Error: need Ip address"
    exit 1
fi

LOGFILE=install.log.txt
rm -f $LOGFILE

ID_RSA=/root/.ssh/cu4_rsa

SSH="ssh -i $ID_RSA root@$RASP_ADR"

DEST=~/raspi

QT_VERSION=5.9

function log 
    local t=`date`
        echo "[$t] $@" | tee -a $LOGFILE


function remote_src 
        local message
        local exitcode
        message=$1
        shift
        log $message
        log "Remote $RASP_ADR command: $@"
        OUT=`$SSH "$@" | tee /dev/tty | tee -a $LOGFILE`
        exitcode=$?
        if [ $exitcode -ne 0 ]; then
                log "Exit with ERROR $exitcode"
                exit $exitcode
        fi


function local_src 
        local message
        local exitcode
        message=$1
        shift
        log $message
        log "Local command: $@"
        OUT=`bash -c "$@" | tee /dev/tty | tee -a $LOGFILE`
        exitcode=$?
        if [ $exitcode -ne 0 ]; then
                log "Exit with ERROR $exitcode"
                exit $exitcode
        fi


function Append_Qt_Module 
        local QtModule
        QtModule=$1
        log "install $QtModule"
        local_src \
        "Clone $QtModule Qt-module" \
        "cd $DEST && git clone git://code.qt.io/qt/$QtModule.git -b $QT_VERSION"
        local_src \
        "Make $QtModule Qt-module" \
        "cd $DEST/$QtModule && $DEST/qt5/bin/qmake -r && make && make install"
        local_src \
        "Synchronize qt5pi with Raspberry pi" \
        "rsync -avz -e \"ssh -i $ID_RSA\" $DEST/qt5pi pi@$RASP_ADR:/usr/local"


local_src \
"open key -> Raspberry" \
"cat /root/.ssh/cu4_rsa.pub | ssh pi@$RASP_ADR \"sudo cat - > authorized_keys; sudo mkdir -p /root/.ssh; sudo mv authorized_keys /root/.ssh; sudo chown -R root:root /root/.ssh\""

remote_src \
"Update System" \
"apt-get update"

remote_src \
"Upgrade System" \
"apt-get -y upgrade"

remote_src \
"Install Synaptic" \
"apt-get -y install synaptic"

remote_src \
"Install Qt libraries" \
"apt-get -y install libfontconfig1-dev libdbus-1-dev libudev-dev"

remote_src \
"Install Xcb" \
"apt-get -y install \"^libxcb.*\" libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev"

remote_src \
"Install Qt-WebKit" \
"apt-get -y install flex bison gperf libicu-dev libxslt-dev ruby"

remote_src \
"Install Qt WebEngine" \
"apt-get -y install libssl-dev libxcursor-dev libxcomposite-dev libxrandr-dev"

remote_src \
"Install Qt Multimedia" \
"apt-get -y install libasound2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev"

DEB_SRC="deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi"
remote_src \
"Проверка открытости deb_src" \
"cat /etc/apt/sources.list | grep -s -G '^$DEB_SRC' | cat"

if [ ! "$OUT" ]
then
    remote_src \
    "Открываем комментарии" \
    "echo '$DEB_SRC' >> /etc/apt/sources.list"
else
    log "DEB_SRC открыты ранее"
fi

remote_src \
"Update System" \
"apt-get update"

remote_src \
"Build dependences for qt4-x11" \
"apt-get -y build-dep qt4-x11"

remote_src \
"Build dependences for libqt5gui5" \
"apt-get -y build-dep libqt5gui5"

remote_src \
"Install more libs for Xcb" \
"apt-get -y install libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0"

remote_src \
"Make dir for Qt libs" \
"mkdir /usr/local/qt5pi; chown pi:pi /usr/local/qt5pi"

remote_src \
"Reboot" \
"reboot"

while true; do
    sleep 1s
    log "wait..."
    $SSH "echo done"
    if [ $? -eq 0 ]; then break; fi
done

local_src \
"Install Git" \
"apt-get -y install git && mkdir -p $DEST && cd $DEST"

local_src \
"Clone RaspberryPi tools" \
"git clone https://github.com/raspberrypi/tools $DEST/tools"

local_src \
"OR Update Raspberry Pi Tools" \
"cd $DEST/tools && git pull origin master"

fi

local_src \
"Synchronize local computer with Raspberry Pi" \
"cd $DEST && mkdir -p /sysroot /sysroot/usr /sysroot/opt && \
rsync -avz -e \"ssh -i $ID_RSA\" root@$RASP_ADR:/lib sysroot && \
rsync -avz -e \"ssh -i $ID_RSA\" root@$RASP_ADR:/usr/include sysroot/usr && \
rsync -avz -e \"ssh -i $ID_RSA\" root@$RASP_ADR:/usr/lib sysroot/usr  && \
rsync -avz -e \"ssh -i $ID_RSA\" root@$RASP_ADR:/opt/vc sysroot/opt && \
rsync -avz -e \"ssh -i $ID_RSA\" root@$RASP_ADR:/usr/local/include sysroot/usr/local && \
rsync -avz -e \"ssh -i $ID_RSA\" root@$RASP_ADR:/usr/local/lib sysroot/usr/local"

local_src \
"Get sysroot-relative.py script" \
"cd $DEST && wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py && \
chmod +x sysroot-relativelinks.py && \
./sysroot-relativelinks.py sysroot "
exit 0

local_src \
"Получаем qtbase версии $QT_VERSION и конфигурируем Qt."
"`git clone -b $QT_VERSION git://code.qt.io/qt/qtbase.git  $DEST/qtbase`"
local_src \
"OR Update qtbase версии $QT_VERSION" \
"cd $DEST/qtbase && git pull origin $QT_VERSION"

local_src \
"Конфигурация и установка Qt$QT_VERSION" \
"cd $DEST/qtbase && ./configure -release -opengl es2 -device linux-rasp-pi3-g++ \
-device-option CROSS_COMPILE=$DEST/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf- \
-sysroot $DEST/sysroot -opensource -confirm-license -make libs -make tools -qt-pcre -optimized-qmake -reduce-exports \
-release -prefix /usr/local/qt5pi -extprefix $DEST/qt5pi -hostprefix $DEST/qt5 -no-use-gold-linker -v && \
make -j 4 && make install"

local_src \
"Change owner to $USERNAME on $DEST" \
"chown -R $USERNAME:$USERNAME $DEST"

local_src \
"Get new free types from http://dejavu-fonts.org" \
"cd $DEST && wget http://sourceforge.net/projects/dejavu/files/dejavu/2.37/dejavu-fonts-ttf-2.37.tar.bz2 && \
tar -xvf dejavu-fonts-ttf-2.37.tar.bz2"

local_src \
"Send type to target dir" \
"cd $DEST && mkdir -p qt5pi/lib/fonts && \
cp dejavu-fonts-ttf-2.37/ttf/DejaVuSansMono.ttf qt5pi/lib/fonts/"

local_src \
"Send libs to RaspberryPi" \

"cd $DEST && rsync -avz -e \"ssh -i $ID_RSA\" qt5pi root@$RASP_ADR:/usr/local"

local_src \
"Build Test application" \
"cd $DEST/qtbase/examples/opengl/qopenglwidget && \
$DEST/qt5/bin/qmake && \
make && \
scp -i $ID_RSA qopenglwidget root@$RASP_ADR:/home/pi "

remote_src \
"Добавляем пути к библиотекам Qt на Raspberry Pi" \
"echo /usr/local/qt5pi/lib | tee /etc/ld.so.conf.d/qt5pi.conf && \
ldconfig"

remote_src \
"Устранение неполадок в библиотеке EGL/GLES " \
"rm /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0 /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0 && \
ln -s /opt/vc/lib/libEGL.so /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0 && \
ln -s /opt/vc/lib/libGLESv2.so /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0 && \
ln -s /opt/vc/lib/libEGL.so /opt/vc/lib/libEGL.so.1 && \
ln -s /opt/vc/lib/libGLESv2.so /opt/vc/lib/libGLESv2.so.2"


remote_src \
"Запуск теста" \
"nohup /home/pi/qopenglwidget > /dev/null 2>&1 &"

log "Please push the some key when you are ready to next operation"
read -n1

remote_src \
"Kill test" \
"pkill qopenglwidget"

#Add youre Qt modules
Append_Qt_Module qtserialport

remote_src \
"Обновляем символьные линки к  библиотекам Qt на Raspberry Pi" \
"ldconfig"

log "DONE!!!!"
exit 0

【讨论】:

【参考方案3】:

我像这样编辑了设备 mkspec 文件linux-rasp-pi3-g++/qmake.conf

VC_LIBRARY_PATH         = $$[QT_SYSROOT]/opt/vc/lib
VC_INCLUDE_PATH         = $$[QT_SYSROOT]/opt/vc/include

QMAKE_LIBDIR_OPENGL_ES2 = $$VC_LIBRARY_PATH
QMAKE_LIBDIR_EGL        = $$QMAKE_LIBDIR_OPENGL_ES2
QMAKE_LIBDIR_OPENVG     = $$QMAKE_LIBDIR_OPENGL_ES2

QMAKE_INCDIR_EGL        = \
                        $$VC_INCLUDE_PATH \
                        $$VC_INCLUDE_PATH/interface/vcos/pthreads \
                        $$VC_INCLUDE_PATH/interface/vmcs_host/linux
QMAKE_INCDIR_OPENGL_ES2 = $$QMAKE_INCDIR_EGL
QMAKE_INCDIR_OPENVG     = $$QMAKE_INCDIR_EGL

QMAKE_LIBS_OPENGL_ES2   = -lGLESv2
QMAKE_LIBS_EGL          = -lEGL -lGLESv2
QMAKE_LIBS_OPENVG       = -lEGL -lOpenVG -lGLESv2

并使用gcc-linaro-4.9-2015.02-3-x86_64_arm-linux-gnueabihf 工具链。

我写了这个可能对你有帮助的博客:Build Qt 5.10 for Raspberry Pi 3

【讨论】:

请注意,如果您想宣传自己的博客,您必须在回答中披露您的隶属关系。否则,您的回答可能会被标记为垃圾邮件。请阅读How to not be a spammer。这次我为您添加了从属关系披露。下次请注意。

以上是关于为树莓派 pi3 交叉编译 Qt 时出错的主要内容,如果未能解决你的问题,请参考以下文章

为 ARM 交叉编译时共享对象导入错误

树莓派+QT5.9.9交叉编译(QT环境配置篇)

Ubuntu Qt 交叉编译(树莓派2b)

为树莓派交叉编译 bcm2835-1.42 库。

QT交叉编译环境

rust 交叉编译树莓派程序