The first time I tried to statically compile the QT application in Linux

Source: Internet
Author: User

The first time I tried to statically compile the QT application in Linux

I originally wanted to release the program compiled in Linux and found that it could not run in Linux without QT. What should we do? I wanted to copy the dynamic link library related to QT (suffixed with so) to my application and then publish it together. I tried it myself. Basically all QT programs require libqtcore. so and libqtgui. so, but I don't know what's going on. I think this is inconvenient. I want to compile the QT source code myself, and I started to compile QT statically.

To compile QT, download the source code from the QT official website. You can download the source code of qt(4.8.3.pdf, and then install it like the familiar tar.gz software. The basic steps are CD./configuremakeinstallmake. After reading a master article, I quickly compiled it. His article is: Here.

It took me one night (I don't know the exact Compilation Time of QT ^_^) to see that QT has been compiled in the morning. In fact, based on my years of experience in windows, I want to use the QT lib library, which is a static library (suffixed with a), because I want to compile QT statically. I found that my/home folder is only over 50 MB! I accidentally compiled example and demo. In particular, example has 4G! Damn it, I decisively deleted the example folder and demo folder, including the bin, include, and Lib folders, and some unused folders add up to a total of G. Okay. I want to try to use the static library as a version so that qtcreator can recognize it. However, you are not easy to learn and will not perform relevant operations! Today I asked the QT forum to see if there are any results.

Next, let's talk about how I solve static compiling of QT applications. I haven't seen this method in other places. For example, I want to statically compile my "texture coordinate resolution" program to be released and add only the header files and source files used by my project to the Pro file.

HEADERS += \    TCWidget.h \    TCCFrame.h \    SingleSelectActions.hSOURCES += \    TCWidget.cpp \    TCCFrame.cpp \    SingleSelectActions.cpp \    main.cpp

However, this is the default dynamic compilation method. I added a "Config + = static" sentence ". How can this be done! My static QT version has not been recognized by qtcreator. So I figured out a way to link the QT library myself!

It is actually quite simple. First, I added these two lines:

HEADERS += \    TCWidget.h \    TCCFrame.h \    SingleSelectActions.hSOURCES += \    TCWidget.cpp \    TCCFrame.cpp \    SingleSelectActions.cpp \    main.cppCONFIG += staticLIBS += /home/jiangcaiyang/QtSDK/Desktop/QtStatic/lib/libQtCore.a \    /home/jiangcaiyang/QtSDK/Desktop/QtStatic/lib/libQtGui.a

Note: There are two methods for libs + =: one is to use the LD program in GCC to load the library, that is, if libqtcore. A can be written in/usr/lib as follows: libs + =-lqtcore. The prefix lib can be used, and the path of the static library is directly specified, I am using the second method. But more than 700 errors! Printing is not complete!

Have you noticed? These library functions have headers, so I guess their library file names, some of which are in libx11.a and some are libxm. a, so in. the following statements are added to the Pro:

HEADERS += \    TCWidget.h \    TCCFrame.h \    SingleSelectActions.hSOURCES += \    TCWidget.cpp \    TCCFrame.cpp \    SingleSelectActions.cpp \    main.cppCONFIG += staticLIBS += /home/jiangcaiyang/QtSDK/Desktop/QtStatic/lib/libQtCore.a \    /home/jiangcaiyang/QtSDK/Desktop/QtStatic/lib/libQtGui.a \    /usr/lib/i386-linux-gnu/libX11.a \    /usr/lib/i386-linux-gnu/libSM.a \    /usr/lib/i386-linux-gnu/libICE.a \    /usr/lib/i386-linux-gnu/libXext.a \    /usr/lib/i386-linux-gnu/libxcb.a \    /usr/lib/i386-linux-gnu/libXau.a \    /usr/lib/i386-linux-gnu/libXdmcp.a

The link was successful! It's just a bug. At runtime, Ubuntu's unity themes were all gone, And the fonts were very ugly!

These errors also occur:

Qobject: setparent: cannot set parent, new parent is in a different thread

Qobject: starttimer: qtimer can only be used with threads started with qthread

Qobject: setparent: cannot set parent, new parent is in a different thread

Qobject: starttimer: qtimer can only be used with threads started with qthread

Qobject: setparent: cannot set parent, new parent is in a different thread

Qobject: starttimer: qtimer can only be used with threads started with qthread

Qobject: setparent: cannot set parent, new parent is in a different thread

Qobject: starttimer: qtimer can only be used with threads started with qthread

Qobject: setparent: cannot set parent, new parent is in a different thread

Qobject: starttimer: qtimer can only be used with threads started with qthread

Use a command prompt with the style parameter, like this: A-stylecleanlooks can still display other theme effects, but it does not have the unity theme effect. It seems that a problem occurs during compilation. I will check the problem again. Write this article as a souvenir.

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.