QT program packaging under Linux

QT program packaging under Linux

        Most of the tutorials about QT program packaging on the Internet are tutorials under Windows. There are few tutorials about QT program packaging under Linux, and most of them are not very detailed. Here I have compiled the following methods about QT program packaging under Linux. For your reference and study, about the method of packaging QT programs under Windows, you can read my other blog "Super Detailed Packaging Tutorial for QT Projects.

        At present, there are two main methods of packaging QT programs under Linux that I have come into contact with: the first one: packaging through scripts. This method is simple and convenient, but the QT programs packaged in this way cannot be placed on another clean computer. It is not recommended to run under the Linux system; the second method is to package the QT program through Linuxdeployqt. It is also very convenient to package the QT program by this method, and the packaged program can be placed in any Linux environment and run directly. Below I will introduce the following two packaging methods in detail. You can choose any packaging method according to your actual usage.

prerequisite preparation

       1. No matter which packaging method is used to package the QT program, it must first be compiled and executed through release to generate the target executable file.

        2. Create a new test folder (it can be any folder).

        3. Find the executable file generated by release and copy it to our newly created test folder. The generated executable files generally exist in the bin directory under the release folder in our project directory. Below is my path along with the executable.

1. Packaging through scripts

        1. Create a new pach.sh script under our newly created test folder.

         The content of the script is as follows: the content after exe is the name of our executable file, the content after des is the path where our test folder is located, and other content does not need to be changed.

#!/bin/sh

exe="FiberConfigTool"

des="/临时文件/test/"

deplist=$(ldd $exe|awk '{if (match($3,"/")){printf("%s "),$3}}')

cp $deplist $des

        2. Give the script permission

         3. Execute the pach.sh script. By executing the script, the libraries that the executable program depends on can be placed in the test folder.

        4. Create a new FiberConfigTool.sh script and give it permission (it can be any name, it is recommended to name it as the name of the executable file).

        The content of the script is as follows: you only need to modify the content after the appname to the name of our executable file, and the others do not need to be changed.

#!/bin/sh  

appname=FiberConfigTool #要运行的程序名

dirname=`dirname $0`

tmp="${dirname#?}"

if [ "${dirname%$tmp}" != "/" ]; then

dirname=$PWD/$dirname

fi

LD_LIBRARY_PATH=$dirname

export LD_LIBRARY_PATH

$dirname/$appname "$@"

         5. Run the FiberConfigTool.sh script to run the program. At this point, the script is packaged.

 2. Packaging through linuxdeployqt

        1. Download linuxdeployqt: https://github.com/probonopd/linuxdeployqt/releases

        2. Rename the downloaded linuxdeployqt-x86_64.AppImage to linuxdeployqt. The previous name is too long and looks awkward.

        3. Give linuxdeployqt permission

        4. Put the modified linuxdeployqt in the /usr/local/bin directory, so that we can run linuxdeployqt anywhere.

         5. Test whether linuxdeployqt is installed successfully. If the following content appears, the installation is successful.

         6. Modify the file bashrc file

        Add the following content at the end of the bashrc file: where /opt/qtcreator-4.14.0/bin is the installation path of QT and can be changed to your own.

#add qt env
export PATH=/opt/qtcreator-4.14.0/bin/:$PATH
export LIB_PATH=/opt/qtcreator-4.14.0/bin/lib:$LIB_PATH
export PLUGIN_PATH=/opt/qtcreator-4.14.0/bin/plugins:$PLUGIN_PATH
export QML2_PATH=/opt/qtcreator-4.14.0/bin/qml:$QML2_PATH

        If you don't know your own QT installation path, you can get it by the following method: whereis qt

         7. Use the source command to make the bashrc file take effect immediately

        8. Test the environment variables to see if they are correct, and see that the qmake version is correct.

        9. Copy the dependent files. If there is an error, just ignore it and wait for the command to complete.

        10. Switch to the newly created test folder, execute the executable file, and check whether the packaging is successful. At this point, the packaging is completed through linuxdeployqt.

Guess you like

Origin blog.csdn.net/qq_47023150/article/details/131105980