Statically compiled QT program under Linux

Source: Internet
Author: User
Tags sqlite

In general, we use QT compiled programs to rely on the system Qt Library, that is, the program moved to another system without the installation of Qt Library is not available. will prompt for missing ... Errors such as library files. This is the result of dynamic compilation.

However, if we want to compile a program, the program will be sent to others, they can open directly, and do not need to install the QT library in particular, it will need to use static compilation.

How to statically compile QT programs under Linux?

First, you need to install the statically compiled QT, that is, the static compilation QT program first requires a statically compiled and installed QT

1, download the source installation program, such as Qt-x11-opensource-src-4.5.1.tar.gz

2. Unzip to a directory

3, CD into the directory after decompression, command:

./configure-static-release-qt-zlib-qt-gif-qt-libpng-qt-libmng-qt-libjpeg-nomake Demos-nomake Examples-qt-sql-sql Ite-prefix/usr/local/trolltech/qt-4.5.1_static

Parameter-static refers to the method of statically compiling QT

Parameter-release refers to a library that compiles only the release version

The parameter-qt-zlib-qt-gif-qt-libpng-qt-libmng-qt-libjpeg is better to determine that QT compiles programs that run under the current unknown system.

Parameter-nomake demos-nomake examples refers to not compiling demos and examples

Parameter-qt-sql-sqlite If you do not have this parameter, configure may indicate that SQLite has a problem and abort.

The parameter-prefix/usr/local/trolltech/qt-4.5.1_static indicates a statically compiled directory of QT installations, named Qt-4.5.1_static, to differentiate between the dynamically compiled and installed QT, because without this parameter, The installation will overwrite QT (if any) that was previously compiled and installed dynamically.

4, no problem after

Make

5, make no problem and then

sudo make install

6. Add (or change) environment variables:

In your home directory, in the directory of your name, append (or change) the following environment variable in the. Profile file: (set some specific environment variables for QT, this is very important!.profile file is hidden, can be in your name directory, press ctrl+h display all files to see)

qtdir=/usr/local/trolltech/qt-4.5.1_static/
Path= $QTDIR/bin: $PATH
Manpath= $QTDIR/doc/man: $MANPATH
Ld_library_path= $QTDIR/lib: $LD _library_path
Export Qtdir PATH MANPATH Ld_library_path
qtdir=/usr/local/trolltech/qt-4.5.1_static/
Path= $QTDIR/bin: $PATH
Manpath= $QTDIR/doc/man: $MANPATH
Ld_library_path= $QTDIR/lib: $LD _library_path
Export Qtdir PATH MANPATH Ld_library_path

7. Restart

8. Test the qmake at the terminal

If successful, the QT program compiled with Qmake is statically compiled. At this point you will find that the statically compiled program size becomes considerably larger.

The difference between static compilation and dynamic compilation

Dynamically compiled executables need to be accompanied by a dynamic-link library that, when executed, calls the commands in their corresponding dynamic-link libraries. So its advantage is to reduce the size of the execution file itself, on the other hand, speed up the compilation speed, saving the system resources. One drawback is that even a simple program that uses only the one or two commands in the link library, with a relatively large library of links, and a dynamically compiled executable cannot run if the corresponding runtime is not installed on other computers. 、

Static compilation is when the compiler compiles the executable file, extracts the part of the corresponding dynamic-link library (. So) that the executable needs to call, and links it to the executable file so that the executable does not depend on the dynamic-link library when it is run. So the pros and cons are just as complementary to the dynamically compiled executable file.

Original address: http://www.linuxidc.com/Linux/2011-02/32537.htm

http://blog.csdn.net/small_qch/article/details/6748712

Statically compiled QT program under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.