Qt5.12 program package release (Linux)

(Linux platform) How do programs compiled by Qt run on other computers without Qt installed? This article will tell you the answer

Compile the project

Here we take an official routine as the target project, and choose Releasethe way to compile the project.

insert image description here
After the compilation is completed, the program runs automatically (as shown in the figure below), finds the location of the executable file (which can be found in the project build directory),

insert image description here

Copy the executable file separately and put it in an empty folder,

insert image description here

The file cannot be run at this time,

insert image description here

Configure Qt's environment variables

Open ~/.bashrc, add the Qt environment variable at the end (set according to your own Qt directory)

insert image description here

#配置Qt环境变量
export PATH=$PATH:/opt/Qt5.12.9/5.12.9/gcc_64/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt5.12.9/5.12.9/gcc_64/lib
export QT_PLUGIN_PATH=$QT_PLUGIN_PATH:/opt/Qt5.12.9/5.12.9/gcc_64/plugins
export QML2_IMPORT_PATH=$QML2_IMPORT_PATH:/opt/Qt5.12.9/5.12.9/gcc_64/qml

After saving, enter it in the terminal source ~/.bashrcor restart the computer to take effect.

download linuxdeployqt

Go to github to directly download the compiled linuxdeployqt-x86_64.AppImageapplication file
Download address: https://github.com/probonopd/linuxdeployqt/releases

insert image description here

run linuxdeployqt

Set linuxdeployqt-x86_64.AppImageit to executable permission, and copy it to the /usr/local/bindirectory at the same time, and by the way, rename the same name,

insert image description here
Use linuxdeployqt app -appimage(app is an executable file) to package,

The first time was unsuccessful. It turned out that ubuntu came with qmakeit, but it was just an empty shell. We need to manually modify qmakethe path.

insert image description here

Modify /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.confthis file (set it according to your own Qt directory),

/opt/Qt5.12.9/5.12.9/gcc_64/bin
/opt/Qt5.12.9/5.12.9

Run it again linuxdeployqt app -appimage, although a few errors are still reported, but it does not affect the use.

insert image description here
At this point, many library files have been added to the packaging directory, and the executable file can also run smoothly (it can also run on other Linux systems without Qt installed):

insert image description here


Due to the variety of Linux distribution systems, Qt programs compiled on ubuntu may not run on other distributions, even on the same ubuntu system. The program I compiled on 16.04 can run on other 16.04 systems (without Qt installed), but not on 14.04.

Guess you like

Origin blog.csdn.net/weixin_43772810/article/details/124077692
Recommended