5

I am currently writing code in Qt. How to compile the code statically?

From Qt document I came to know the following step

1) Visual Studio 2008 -> commandPrompt -> QtDir -> configure -static -> nmake

But, it took 17 GB and at the end it exited before the completion stating that "the space is not enough".

Is there any simple way to compile the Qt application as a stand alone program?

2
  • 6
    (1) Google knows. (2) Saying "codes" when referring to a program should be a punishable offense. Commented Nov 6, 2010 at 11:53
  • 1
    If you're statically linking do Qt you should be aware of the potential licensing issues. Last time I checked Nokia seemed to follow the opinion that statically linking to an LGPL library places the resulting program under LGPL as well. Commented Apr 26, 2011 at 10:07

2 Answers 2

8

You have already used the only way possible: compiling the source as static.

Some things that have a very large impact on disk size (which seems to be the problem here), with corresponding configure arguments:

  1. Disable debug: -release
  2. Disable modules you don't need, especially QtWebKit: -no-webkit -no-script -no-scripttools -no-qt3support -nomake demos -nomake tools -nomake examples
  3. Disable LTCG support, which has the nasty side effect of generating huge static libraries: no-ltcg

These should help keep the build size to a minimum.

Sign up to request clarification or add additional context in comments.

7 Comments

@rubenvb Can you give a rough estimation for required disk space
I would say less than 7 GB for a 32-bit compile, but that's a really rough estimate. You can delete most of the created files by running del /S /Q *.o afterwards, which removes all the object files.
@rubenvb But without the object files how can it run?
The object files (*.obj for MSVC, *.o for GCC) are nothing more than unlinked compiled *.cpp files. When building a library, all these files are put together in a *.lib (for MSVC, *.a for GCC) and maybe a DLL, when building shared libraries. The object files themselves are never used anymore. Your Qt project links instead with the produced libraries.
I got ERROR: Unknown command line option '-no-webkit', why?
|
1

For more modern versions of Qt (i.e. Qt 6.*), the size-reduction flags mentioned above will not work. See my answer here for a comprehensive list of ways to reduce compile time/size.

Hope this helps!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.