Linux下交叉环境的编译Qt程序(Qt5,nvidia tx2,Ubuntu,arm)

1.linux主机准备

qt的安装

qtcreator 3.5.1 qt5.5.1

g++的安装

apt-get install g++

安装opengl库

apt-get install build-essential libgl1-mesa-dev

2.安装交叉编译器

下载交叉编译器

  ​​​​​​gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz

解压

tar -zxvf ​​​​​​gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz

放到/opt目录下

cp -r ​​​​​​gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/ /opt/

配置环境变量

nano /etc/profile
添加
export PATH=/opt/​​​​​​gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin:$PATH

生效source /etc/profile,或者重启
查看是否生效

aarch64-linux-gnu-g++ -v

3.下载qt源码,编译出交叉编译版的qmake

qt官网download.qt.io/archive/qt/

例如下载qt5.9.1

Index of /archive/qt/5.9/5.9.1/single

(1) 在home下创建Qt5.9.1文件夹

mkdir /opt/Qt5.9.1


(2) 拷贝解压

tar xvzf qt-everywhere-opensource-src-5.9.1.tar.xz


(3) 修改

qtbase/mkspecs/linux-aarch64-gnu-g++/qmake.conf


修改如下:
 

#
# qmake configuration for building with aarch64-linux-gnu-g++
#

MAKEFILE_GENERATOR      = UNIX
CONFIG                 += incremental
QMAKE_INCREMENTAL_STYLE = sublib

QT_QPA_DEFAULT_PLATFORM = linuxfb

QMAKE_CFLAGS_RELEASE   += -O2 -march=armv8-a

QMAKE_CXXFLAGS_RELEASE   += -O2 -march=armv8-a

include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)

# modifications to g++.conf
QMAKE_CC                = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc
QMAKE_CXX               = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++
QMAKE_LINK              = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++
QMAKE_LINK_SHLIB        = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++

# modifications to linux.conf
QMAKE_AR                = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-ar cqs
QMAKE_OBJCOPY           = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-objcopy
QMAKE_NM                = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-nm -P
QMAKE_STRIP             = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-strip
load(qt_config)
#houyawei 2022.4.26

(4) 回到源码文件根目录下运行

	sudo ./configure -prefix /opt/Qt5.9.1/ -release -linuxfb -opensource -optimized-qmake -xplatform linux-aarch64-gnu-g++ -no-opengl -skip qt3d -skip qtcanvas3d -nomake examples -skip qtdeclarative -no-iconv


(5) 在源码文件根目录下运行:(耗时较长)

sudo make


(6) 等待运行完,运行

make -j4


(7) 等待运行完,先在opt下创建Qt5.9.1文件夹,运行

sudo make install

4.配置环境变量

(1)配置环境变量到/etc/profile

	export QTEDIR=/opt/Qt5.9.1:$QTEDIR
	export PATH=/opt/Qt5.9.1/bin:$PATH
	export LD_LIBRARY_PATH=/opt/Qt5.9.1/lib: LD_LIBRARY_PATH

(2) source /etc/profile ,或者重启
(3)检验qmake的版本
 

输入 qmke -v 查看是否在opt/Qt5.9.1下

5.配置qt creator

此处有坑,可尝试重启Linux主机或者重启软件,并注意以下配置

Linux下交叉环境的编译Qt程序(Qt5,nvidia tx2,Ubuntu,arm)_第1张图片

Linux下交叉环境的编译Qt程序(Qt5,nvidia tx2,Ubuntu,arm)_第2张图片

Linux下交叉环境的编译Qt程序(Qt5,nvidia tx2,Ubuntu,arm)_第3张图片

Linux下交叉环境的编译Qt程序(Qt5,nvidia tx2,Ubuntu,arm)_第4张图片

 6.编译运行 

不能直接在Linux主机上运行,可使用file对比查看x86_64,arm_64编译出的可执行文件格式。

程序移动到tx2上,运行正常。

其它的一些问题

1)tx2上缺少库error while loading shared libaries:libqt5charts

apt seatch xxxxx(根据关键字找准确的库名)

apt-get install 库名

2)fatal error: sqlite3.h: No such file or directory

linux 主机可直接安装

sudo apt-get install sqlite3
sudo apt-get install libsqlite3-dev

 使用交叉编译时仍找不到,把头文件放到交叉编译环境即可,例如

cp /usr/include/sqlite3.h /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/libc/usr/include/

3)编译时出错

toolchain.prf(50): system(execute) requires one or two arguments.

下面方法测试有效

In file mkspecs/features/default_pre.prf I commented last line "load(toolchain)"

参考链接:

ubuntu系统X86环境下配置TX2的ARM环境的交叉编译链_guijiaqing的博客-CSDN博客ubuntu的X86环境下安装TX2的ARM交叉编译链https://blog.csdn.net/guijiaqing/article/details/105357779

嵌入式QT环境搭建:No tools chain can produce code for this qt version please define one or more tool chains_Devin-zhou的博客-CSDN博客在编译好qt源代码后,手动将其添加至qtcreator里,qt前面出现感叹号,并出现如下的错误:No tools chain can produce code for this qt version please define one or more tool chains。解决的方案如下:在tools里面的options的build&run,在tool chains里添加gcc的路径,具...https://blog.csdn.net/xiaopang1122/article/details/80411503

Linux下的Qt环境搭建(arm交叉编译)_xflySnail的博客-CSDN博客_qt交叉编译armLinux下的Qt环境搭建(arm交叉编译)Qt环境安装应用安装gl库安装交叉编译器配置交叉编译器到qtcreator创建应用编译运行设置成开机自启动注意:本文软件环境为在虚拟机里搭建的ubuntu-14.04.5-desktop-amd64.iso,虚拟机版本VMware-workstation-full-9.0.0,如果链接中内容发生迁移无法下载可留下联系方式,虚拟机系统安装过程本文不做讲解...https://blog.csdn.net/u012902367/article/details/87876079?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165093461216780357217121%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=165093461216780357217121&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~baidu_landing_v2~default-4-87876079.142%5Ev9%5Econtrol,157%5Ev4%5Econtrol&utm_term=qt%E4%BA%A4%E5%8F%89%E7%BC%96%E8%AF%91&spm=1018.2226.3001.4187 toolchain.prf(50): system(execute) requires one or two arguments. | Qt Forum@titan83 - usualy it's when you've configured your compiler path to gcc instead of g++. You can try to check that and uncomment (get back) your line at the end of default_pre.prf file. I wonder if it help?https://forum.qt.io/topic/83153/toolchain-prf-50-system-execute-requires-one-or-two-arguments/4

//houyawei  2022.4.26 

你可能感兴趣的:(nvidia,linux,qt5,交叉编译,arm)