Ubuntu下编译QT

1. 下载源码
wget https://download.qt.io/official_releases/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.tar.xz
tar xf qt-everywhere-src-5.15.2.tar.xz
cd qt-everywhere-src-5.15.2
2. 安装依赖库

sudo apt update
sudo apt install build-essential libgl1-mesa-dev libx11-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libxcb1-dev libx11-xcb-dev libxcb-glx0-dev libfontconfig1-dev libfreetype6-dev libfreetype6 libxcursor-dev libxinerama-dev libxrandr-dev libxss-dev libnss3-dev libxcrypt-dev libcap-dev libxcursor-dev libxdamage-dev libxcomposite-dev libglu1-mesa-dev libgcrypt20-dev libudev-dev libpci-dev libssl-dev mesa-common-dev

sudo apt-get install libx11*
sudo apt-get install libxcb-*
sudo apt-get install libxkbcommon-devsudo
sudo apt-get install libxkbcommon-x11-dev
sudo apt-get install libxcb-xinerama0-dev
sudo apt-get install libxcb-sync-dev
sudo apt install libnss3-dev
sudo apt-get install libfontconfig1-dev 
sudo apt-get install libxtst-dev
sudo apt-get install libxcomposite-dev
sudo apt-get install libxkbfile-dev
sudo apt-get install libxcursor-dev
sudo apt install dbus dbus-tests libdbus-glib-1-dev
sudo apt install llvm
sudo apt-get install libclang-dev
sudo apt install gperf
sudo apt install bison flex
sudo apt install nodejs npm 
sudo apt update && sudo apt install -y python2.7 python2.7-dev

3. 编译安装
 

./configure -prefix /opt/qt5.15.2 -release -opensource -confirm-license -webengine-proprietary-codecs

make -j$(nproc)
sudo make install
export PATH=/opt/qt5.15.2/bin:$PATH

4.编译错误

(1)/../3rdparty/chromium/third_party/perfetto/src/trace_processor/containers/string_pool.h:256:34: error: ‘numeric_limits’ is not a member of ‘std’

找到对应文件添加:#include <limits>  // 引入包含 std::numeric_limits 的头文件

/usr/include/c++/11/bits/stl_algobase.h:254:5: note: template argument deduction/substitution failed: ../../3rdparty/chromium/third_party/breakpad/breakpad/src/client/linux/handler/exception_handler.cc:141:49: note: deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘long int’) 141 | static const unsigned kSigStackSize = std::max(16384, SIGSTKSZ);

打开文件 /opt/Qt/5.15.2/Src/qtwebengine/src/3rdparty/chromium/third_party/breakpad/breakpad/src/client/linux/handler/exception_handler.cc

修改141行static const unsigned kSigStackSize = std::max(16384, SIGSTKSZ);改为static const unsigned kSigStackSize = std::max(static_cast<long>(16384), SIGSTKSZ);

(2)g++: fatal error: 已杀死 signal terminated program cc1plus compilation terminated.c

使用

dmesg | grep -i 'out of memory\|killed process'

查看错误原因:

显示为root@lxm-virtual-machine:/home/lxm/qt-everywhere-src-5.15.2# dmesg | grep -i 'out of memory\|killed process' [48315.600660] Out of memory: Killed process 1320838 (cc1plus) total-vm:2345276kB, anon-rss:1406456kB, file-rss:128kB, shmem-rss:0kB, UID:0 pgtables:4488kB oom_score_adj:0 [50509.874153] Out of memory: Killed process 1327974 (cc1plus) total-vm:2349236kB, anon-rss:968884kB, file-rss:0kB, shmem-rss:0kB, UID:0 pgtables:4480kB oom_score_adj:0。

说明内存不足,由于我是用的是虚拟机,设置了2核4G内存,把参数改大后就不再出现这个问题了。

(3)安装qt creator后配置qmake指向自己编译的qmake

(4)编译的没有linuxdeployqt

下载源码 https://github.com/probonopd/linuxdeployqt/releases,解压后,使用qt打开pro工程文件,进行编译。编译完成后拷贝到自己的自己编译的qt目录/bin下

(5)linuxdeployqt打包找不到第三方库,在调用命令前设置临时环境变量,在打包:

export LD_LIBRARY_PATH=/home/lxm/Loong3/libs/assimp/ubuntu/lib/:/home/lxm/Loong3/libs/ffmpeg4.2.9/ubuntu/lib/:/home/lxm/Loong3/libs/libssh2/ubuntu/lib:$LD_LIBRARY_PATH
'/opt/qt5.15.2/bin/linuxdeployqt'  '/home/lxm/build-Loong3-Replacement_for_Desktop_Qt_5_15_2_GCC_64bit-Release/Loong3' -qmldir=/home/lxm/Loong3/

(6)调试提示QML.QtQuick.Window2.15.Window, QML.Window没有可用文档。

打开 ~/.bashrc,在末尾追加如下内容

export PATH="$PATH:$QTDIR/bin"
export LD_LIBRARY_PATH="/opt/qt5.15.2/lib"
export QML2_IMPORT_PATH="/opt/qt5.15.2/qml"
export QT_PLUGIN_PATH="/opt/qt5.15.2/plugins"

如果不好用,可以在项目-运行-环境中添加

(7)调试提示

注意:file:///usr/lib/x86_64-linux-gnu/qt5/qml/QtQuick/Controls.2/qmldir此处还是去找了原来的目录。首先运行命令检查自己编译的模块是否存在,运行如下命令:

# 检查自定义Qt的QtQuick.Controls.2模块是否存在
ls /opt/qt5.15.2/qml/QtQuick/Controls.2/
# 关键文件:qmldir(模块描述)和libqtquickcontrols2plugin.so(插件)
ls /opt/qt5.15.2/qml/QtQuick/Controls.2/qmldir
ls /opt/qt5.15.2/qml/QtQuick/Controls.2/libqtquickcontrols2plugin.so

如果模块都存在,移除原来的目录:

sudo mv /usr/lib/x86_64-linux-gnu/qt5/qml/QtQuick/Controls.2{,.bak}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值