简体   繁体   中英

How do I compile my Qt application into a static library?

I have a complicated backend (and compile process as well) to my main project. Hence, I dont want to introduce all of the extra things that building a Qt Gui requires to that system.

Therefore, I want to compile the Qt GUI side statically and then add a little -lmygui into my build process at the end.

NOTE: This isnt to say that I want all of the Qt libraries to be built statically (doing so would violate the LGPL). Essentially, it should be the same as if i build the backend statically and linked that into qt (which would be my second option, but is an inferior solution).

How do I do this?

I'm going to assume that you are using qmake project files (.pro) for building this library. If you're doing it that way, just replace the TEMPLATE=app section of the .pro file with this:

TEMPLATE=lib
CONFIG+=staticlib

simply, you cant do just that. Qt requires more than a -mygui, if you use signals and slots in your classes, you will also need to run the 'moc' executable, that will parse your c++ files and generate 'moc_sources.cxx' files, that will also be compiled with your project. there's no way to just link against qt without running moc, and if you use *.ui files for your interface, you will also need to run uic, that will generate the apropriate sources.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM