Ubuntu20上搭建树莓派4B的交叉编译开发环境
说明:最近在公司上到⼀块树莓派4B的板⼦,写了个Python⽂件在上⾯跑,可能后⾯会写点有UI的东西,所以决定先把QT的环境搭建起来,去百度搜了⼀⼤圈,按照操作,最后在安装32库的时候总是失败。⽽且⼤部分⽂章到后⾯就讲得不是很详细了。对我这⼩⽩不太友好。后⾯再youtube上看到了个视频,有详细的操作过程。我把操作的具体流程复制了过来。希望可以有参考作⽤,有条件的也可以去搜⼀下那个视频。⼤致可以分成下⾯⼏步:
1、升级树莓派,再树莓派上安装有⽤到的库。我升级的时候提⽰我容量不⾜,最后没办法只能⽤本地升级,我看了⼀下,我安装的树莓派固件其实也挺新的了,不升级也可以。另外树莓派的源也要换成国内源先,不然要搞很久的。
2、安装交叉编译⼯具,视频⾥⾯说不⽤树莓派官⽅提供的⼯具包了,太⼤,⽽且过时了,去Linaro下载树莓派官⽅推荐的。
3、将树莓派上的⼀些⽂件同步回Ubuntu,修改⼀些链接的指向,后⾯配置Qt⽣成交叉编译的qmake会⽤到。
4、Qt源码的config和make和install。
5、安装Qtcreator,配置和测试。
⼀、树莓派上的操作
sudo vi /etc/apt/sources.list
取消注释
sudo apt update
sudo apt full-upgrade
sudo reboot
sudo rpi-update  //提⽰容量不⾜,先本地升级吧,也很快。具体操作百度⼀下就有了
打开ssh功能 //树莓派怎么打开ssh,百度⼀下就有了
记录下repo 版本,下次可能会⽤到。cat boot/.frimware
⽤到的时候:sudo rpi-update xxxx 就可以恢复到这个版本。这⾥先不管。
确保这两个库存在
sudo reboot
sudo apt-get build-dep qt5-qmake
sudo apt-get build-dep libqt5webengine-data
sudo apt-get install libboost1.58-all-dev libudev-dev libinput-dev libts-dev libmtdev-dev libjpeg-dev libfontconfig1-dev
sudo apt-get install libssl-dev libdbus-1-dev libglib2.0-dev libxkbcommon-dev libegl1-mesa-dev libgbm-dev libgles2-mesa-dev mesa-common-dev
sudo apt-get install libasound2-dev libpulse-dev gstreamer1.0-omx libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-alsa
sudo apt-get install libvpx-dev libsrtp0-dev libsnappy-dev libnss3-dev
sudo apt-get install "^libxcb.*"
sudo apt-get install flex bison libxslt-dev ruby gperf libbz2-dev libcups2-dev libatkmm-1.6-dev libxi6 libxcomposite1
sudo apt-get install libfreetype6-dev libicu-dev libsqlite3-dev libxslt1-dev libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libgstreamer0.10-dev gstreamer-tools libraspberrypi-dev libx11-dev libglib2.0-dev
sudo apt-get install freetds-dev libsqlite0-dev libpq-dev libiodbc2-dev firebird-dev libjpeg9-dev libgst-dev libxext-dev libxcb1 libxcb1-dev libx11-xcb1
sudo apt-get install libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev
ubuntu怎么安装pythonsudo apt-get install libxcb-sync1 libxcb-sync-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev
sudo apt-get install libxcb-glx0-dev libxi-dev libdrm-dev libssl-dev libxcb-xinerama0 libxcb-xinerama0-dev
sudo apt-get install libatspi-dev libssl-dev libxcursor-dev libxcomposite-dev libxdamage-dev libfontconfig1-dev
sudo apt-get install libxss-dev libxtst-dev libpci-dev libcap-dev libsrtp0-dev libxrandr-dev libnss3-dev libdirectfb-dev
libaudio-dev
sudo mkdir /usr/local/qt5pi
sudo chown pi:pi /usr/local/qt5pi
⼆、ubuntu上的操作
sudo apt-get update
sudo apt-get upgrade
ping 树莓派ip 192.168.2.125
sudo bash
apt-get install gcc git bison python gperf pkg-config
apt install make
apt install libclang-dev
apt install build-essential
mkdir /opt/qt5pi
chown ulas:ulas /opt/qt5pi
cd /opt/qt5pi/
tar xf gcc-linaro-7.5.0-2019.12-x86_64_
export PATH=$PATH:/opt/qt5pi/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin
nano ~/.bashrc  //这⾥⽤vi在最后⾯把导出环境变量加上
tar xf qt-everywhere-src-5.14.
cat qt-everywhere-src-5.14.2/qtbase/mkspecs/linux-arm-gnueabi-g++/f  //这个可以仔细来阅读⼀下
将树莓派上的⽂件同步回来:
ping 192.168.2.125 //树莓派的IP
rsync -avz pi@192.168.2.125:/lib sysroot
rsync -avz pi@192.168.2.125:/usr/include sysroot/usr
rsync -avz pi@192.168.2.125:/lib sysroot
rsync -avz pi@192.168.2.125:/usr/lib sysroot/usr
rsync -avz pi@192.168.2.125:/opt/vc sysroot/opt
ls sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.1.0
mv sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.1.0 sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.1.0_backup ln -s sysroot/opt/vc/lib/libEGL.so sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.1.0
mv sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.1.0 sysroot/usr/lib/arm-linux-
gnueabihf/libGLESv2.so.2.1.0_backup
ln -s sysroot/opt/vc/lib/libGLESv2.so sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.1.0
mv sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.1.0 sysroot/usr/lib/arm-linux-
gnueabihf/libGLESv2.so.2.1.0_backup
ls sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.1.0
ln -s sysroot/opt/vc/lib/libGLESv2.so sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.1.0
ln -s sysroot/opt/vc/lib/libEGL.so sysroot/opt/vc/lib/libEGL.so.1
ln -s sysroot/opt/vc/lib/libGLESv2.so sysroot/opt/vc/lib/libGLESv2.so.2
chmod +x sysroot-relativelinks.py
./sysroot-relativelinks.py sysroot
重新检查⼀下:
rsync -avz pi@192.168.16.25:/lib sysroot  //这也是树莓派的ip
rsync -avz pi@192.168.16.25:/usr/include sysroot/usr
rsync -avz pi@192.168.16.25:/usr/lib sysroot/usr
rsync -avz pi@192.168.16.25:/opt/vc sysroot/opt/
./sysroot-relativelinks.py sysroot
mkdir qt5build
cd qt5build/
.
./qt-everywhere-src-5.14.2/configure -opengl es2 -device linux-rasp-pi4-v3d-g++ -device-option
CROSS_COMPILE=/opt/qt5pi/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- -sysroot
/opt/qt5pi/sysroot -prefix /usr/local/qt5pi -opensource -confirm-license -skip qtscript -skip qtwayland -skip qtdatavis3d -nomake examples -make libs -pkg-config -no-use-gold-linker -v
如果说g++没到,就先
apt install build-essential
make -j8
这⼀步我等了⼀个下午,花了4个⼩时吧,主要是忘记配置虚拟机,把多⼏个CPU的核⼼分配给虚拟机了,即使输⼊了j8,实际电脑CPU也没有多核在编译。这⾥还要先把虚拟机的内存分配⼤点,不然中间会提⽰错误,不到g++什么的。
make install
ls /opt/qt5pi/sysroot/usr/local/qt5pi/bin/qmake    //可以看到qmake出现了
将⽂件同步回树莓派:
cd /opt/qt5pi/
rsync -avz sysroot/usr/local/qt5pi pi@192.168.2.125:/usr/local
安装qt creator,配置:
apt-get install qtcreator
Lets create simple Hello world console application. With qt-creator choose new console application
Go to path where your pro file stays.
Call the qmake with command
/opt/qt5pi/sysroot/usr/local/qt5pi/bin/qmake
then hit enter after that you will see the Makefile . Check with the ls command
to create a executable binary just
make
As it seen with file untitled, it is for ARM not intel.
Send it to the raspberr pi with
scp untitled root@192.168.16.25:/home
Back to raspberry pi. Go to home. Then ./untitled Hello World.
Tool->options
Compliers->Add->GCC->C
添加编译器,ABI选择custom

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。