6

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?

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
prabhakaran
  • 4,706
  • 13
  • 63
  • 103
  • 6
    (1) Google knows. (2) Saying "codes" when referring to a program should be a punishable offense. –  Nov 06 '10 at 11:53
  • 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. – Martin Ba Apr 26 '11 at 10:07

1 Answers1

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.

rubenvb
  • 69,525
  • 30
  • 173
  • 306
  • @rubenvb Can you give a rough estimation for required disk space – prabhakaran Nov 06 '10 at 13:36
  • 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 Nov 06 '10 at 14:03
  • @rubenvb But without the object files how can it run? – prabhakaran Nov 06 '10 at 17:13
  • 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. – rubenvb Nov 07 '10 at 11:48
  • @rubenvb it worked superb, and the total size it took was <100mb – prabhakaran Nov 18 '10 at 14:08
  • @prabhakaran: that's great to hear, glad I could help out! – rubenvb Nov 18 '10 at 22:07
  • I got `ERROR: Unknown command line option '-no-webkit'`, why? – KcFnMi May 03 '20 at 06:08