Static QT program compilation in Linux/Ubuntu

Source: Internet
Author: User

In general, the program compiled with QT depends on the system QT library, that is, it cannot be used to move to other systems without the QT library installed. Will prompt missing ...... Library files and other errors. This is the result of dynamic compilation.

However, if we want to compile a program, which can be opened directly after it is sent to others, without having to install the QT Library first, we need to use static compilation.

In Linux, how does one statically compile the QT program?

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

1. Download the source installer, such as qt-x11-opensource-src-4.5.1.tar.gz

2. decompress the package to a directory.

3. Run the CD command to enter the decompressed directory:

. /Configure-static-release-QT-zlib-QT-GIF-QT-libpng-QT-libmng-QT-libjpeg-nomake demos-nomake examples-QT-SQL-SQLite-Prefix /usr/local/trolltech/Qt-4.5.1_static

Parameter-static refers to the method for static QT compilation.

Parameter-release refers to the database that only compiles the release version.

The-QT-zlib-QT-GIF-QT-libpng-QT-libmng-QT-libjpeg parameter is used to better determine that the program compiled by QT can run on unknown systems.

-Nomake demos-nomake examples indicates that demos and examples are not compiled.

If the parameter-QT-SQL-SQLite does not have this parameter, you may be prompted to suspend SQLite due to a problem during configure.

The parameter-Prefix/usr/local/trolltech/Qt-4.5.1_static specifies the directory for static-compiled QT installation, and the named Qt-4.5.1_static is used to differentiate the dynamic-compiled QT installation since if this parameter is not available, during installation, the QT (if any) that was dynamically compiled and installed will be overwritten ).

4. No problem

Make

5. Make is OK and then try again

Sudo make install

6. Add (or change) environment variables:

In the directory under your home directory, append (or change) the following environment variables in the. profile file: (it is very important to set some specific environment variables for Qt !. Profile files are hidden. You can press Ctrl + H to display all files under your name directory)

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 qmake on the terminal.

If it succeeds, the QT program compiled with qmake uses static compilation. At this time, you will find that the size of the statically compiled program is quite large.

Differences between static compilation and dynamic compilation

A dynamically compiled executable file must be accompanied by a dynamic link library. During execution, the corresponding commands in the dynamic link library must be called. Therefore, the advantage is that it reduces the size of the execution file and accelerates compilation and saves system resources. The disadvantage is that even a very simple program only uses one or two commands in the Linked database and requires a relatively large Linked database; second, if the corresponding Runtime Library is not installed on other computers, dynamic compiled executable files cannot be run. ,

Static compilation is the dynamic link library (. so), link to the executable file, so that the executable file does not depend on the dynamic link library during running. So its advantages and disadvantages are exactly complementary to the dynamic compiled executable files.

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

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.