Static compiling of QT in Linux

Source: Internet
Author: User

When QT is installed using the compilation method, the default Compilation Method in the configuration is dynamic compilation, but sometimes the program you write is to be released, it is very cumbersome to bring a lot of dynamic library files, in this case, you need to statically compile your program. To achieve static compilation, the library file must also be statically compiled. So here we will introduce how to perform static compilation by QT.

Step 1: Download the source code package

QT/X11 version: qt-x11-opensource-src-x.x.x.tar.gz

Step 2: Extract

Tar zxvf qt-x11-opensource-src-x.x.x.tar.gz

Step 3: Go to the decompressed folder and configure it as follows:

. /Configure-release-platform Linux-G ++-64-static-nomake examples-nomake demos-no-qt3support-no-script-no-scripttools-no-multimedia-no-audio- backend-no-OpenSSL-no-OpenGL-no-WebKit-no-phonon-no-SQL-SQLite

Step 4: After successful configuration in the previous step, you can compile

Make or gmake

Step 5: Install

Make install or gmake install

Step 6: Configure environment variables:

# Vi/root/. bash_profile // open the root user. bash_profile File
Set the environment variables in the root user. bash_profile file, and add the following content to the file:
Qtdir =/usr/local/trolltech/Qt-x.x.x {QT actual installation path}
Path = $ qtdir/bin: $ path
Manpath = $ qtdir/doc/MAN: $ manpath
LD_LIBRARY_PATH = $ qtdir/lib: $ LD_LIBRARY_PATH
Export qtdir path manpathld_library_path

Then save

Source/etc/profile make the environment variable take effect.

In this way, the QT environment is established.

 

The next step is to install the QT-SDK. You only need to install creator and do not need to install the library !!!

After the installation is complete, set the qmake path:

Open the qtcreator interface:

Tools-> options-> QT-> qmake location:/usr/local/trolltech/Qt-x.x.x/bin/qmake

--------------------------------------------------------------

The following may be windows ::::

When QT is installed using the compilation method, the default Compilation Method in the configuration is dynamic compilation, but sometimes the program you write is to be released, it is very cumbersome to bring a lot of dynamic library files, in this case, you need to statically compile your program. To achieve static compilation, the library file must also be statically compiled. So here we will introduce how to perform static compilation by QT.

Step 1: Download the source code package

QT/X11 version: qt-x11-opensource-src-4.5.2.tar.gz

Step 2: Extract

Tar zxvf qt-x11-opensource-src-4.5.2.tar.gz

Step 3: Go to the decompressed folder and configure it as follows:

./Configure-release-platform win32-msvc2008-static-nomake examples-nomake demos-no-qt3support-no-script-no-scripttools-no-multimedia-no-audio-backend-no-OpenSSL
-No-OpenGL-no-WebKit-no-phonon-no-SQL-SQLite

Step 4: After successful configuration in the previous step, you can compile

Make or gmake

Step 5: Install

Make install or gmake install

Step 6: Configure environment variables:

# Vi/root/. bash_profile // open the root user. bash_profile File
Set the environment variables in the root user. bash_profile file, and add the following content to the file:
Qtdir =/usr/local/Qt-4.5.2
Path = $ qtdir/bin: $ path
Manpath = $ qtdir/doc/MAN: $ manpath
LD_LIBRARY_PATH = $ qtdir/lib: $ LD_LIBRARY_PATH
Export qtdir path manpathld_library_path

Then save

Source/etc/profile make the environment variable take effect.

In this way, the QT environment is established.

How can I compile my own program statically?

Then, add the static option to the MAKEFILE file or add qmake_lflags + =-static to the. Pro file to connect to the static library.

Find the makefile in the program directory and modify the MAKEFILE file as follows:

Cxxflags =-static-pipe-wall-w-O2-fomit-frame-pointer-pipe-March = i586-mcpu = pentiumpro-dqt_no_debug-dqt_shared-dqt_thread_support

Then make.

Ls-l ***

Check whether your target execution file is large?

So far.

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.