(Linux platform) How do programs compiled by Qt run on other computers without Qt installed? This article will tell you the answer
Article directory
Compile the project
Here we take an official routine as the target project, and choose Release
the way to compile the project.
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),
Copy the executable file separately and put it in an empty folder,
The file cannot be run at this time,
Configure Qt's environment variables
Open ~/.bashrc
, add the Qt environment variable at the end (set according to your own Qt directory)
#配置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 ~/.bashrc
or restart the computer to take effect.
download linuxdeployqt
Go to github to directly download the compiled linuxdeployqt-x86_64.AppImage
application file
Download address: https://github.com/probonopd/linuxdeployqt/releases
run linuxdeployqt
Set linuxdeployqt-x86_64.AppImage
it to executable permission, and copy it to the /usr/local/bin
directory at the same time, and by the way, rename the same name,
Use linuxdeployqt app -appimage
(app is an executable file) to package,
The first time was unsuccessful. It turned out that ubuntu came with qmake
it, but it was just an empty shell. We need to manually modify qmake
the path.
Modify /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf
this 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.
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):
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.