PDA

View Full Version : How to create finished executable?



Pyrrha
11th August 2011, 22:46
I know this is a noob question and that it's been asked before, but I am still stuck and I've been trying to get this to work for the past 6 days, so I'm resorting to asking here.

I'm relatively new to programming. I only know a little C++ and just started trying to learn Qt last week. I have a program (a stat point calculator for a game I play) that I wrote as a console application in C++ using Dev C++. That worked flawlessly. Then I installed QtSDK v1.1.2 with Qt Creator 2.2.1 and Qt libraries version 4.7.3, and I attempted to recreate it in a GUI form. This was also a success. When building and running it in Qt Creator, it looks and behaves as it should.

What I can't figure out is how to make an executable or package that I can distribute to others (fellow players who would like to use it). I understand the basic idea that Qt defaults to dynamic linking, and I guess this creates a software package that can be installed? I'm not sure, because I haven't figured out how to do this.

Ideally, I'd prefer a standalone executable for this program, which I'm also aware requires static linking. For the past 6 days I've tried uninstalling and reinstalling various version of Qt, mingw, Qt Creator, as well as the whole Qt SDK bundle, every combination of configure -static -release, mingw32-make, and other commands I got from tutorials, but nothing has worked. Everything I tried either isn't possible (because the tutorial was outdated and didn't apply to any versions I could get my hands on) or resulted in errors I couldn't figure out how to resolve.

Apparently I'm not the only one with this problem.
http://www.qtcentre.org/threads/43371-is-there-no-quot-configure-quot-file-in-qt-sdk-1.1.2

Is there a step-by-step, TOTALLY NOOB-FRIENDLY guide anywhere on how to deploy applications built in the Qt Creator, statically or dynamically? I mean hold-my-hand walk-through style. Please don't link me to the top 20 Google results for this, because I've already tried literally EVERY SINGLE LINK I got from Google searches on this topic, and none of the instructions on them worked or I couldn't figure out how to follow them. When people say things like "make sure your path is properly set," I have no idea what that means or how to do it. It took me all of 2 hours to write the whole program and learn enough Qt to bring it to GUI form, but 6 days and I still can't make a distributable executable. Help!

Pyrrha
12th August 2011, 01:42
Here is the most common tutorial I find, and this is where I get stuck on it.

*Installed QtSDK 4.7.3 for Windows. Working on Windows 7 64-bit Professional.

TUTORIAL 1:
URL: doc.qt.nokia.com/qq/qq10-windows-deployment.html

1. Open a command prompt and enter the following:


cd %QTDIR%

configure -static <any other options you need

What I did:

cd C:\QtSDK (there is no C:\Qt)

configure -static
Output:

'configure' is not recognized as an internal or external command, operable program or batch file.

What I did:

Searched the QtSDK directory for 'configure'

Search returned:


C:\QtSDK\Symbian\tools\sbs\win32\mingw\info\config ure.info


C:\QtSDK\Symbian\tools\gcce4\share\doc\symbian-adt-arm-none-symbianelf\html\gdb\Configure-Options.html


C:\QtSDK\Simulator\Qt\mingw\configure.cache


END OF ATTEMPT

I cannot figure out the appropriate place to run this command in.

TUTORIAL 2:
URL: cartan.cas.suffolk.edu/qtdocs/deployment-windows.html
URL: doc.qt.nokia.com/latest/deployment-windows.html
URL: qt.developpez.com/doc/4.7/deployment-windows/

1. Open a command prompt and enter the following:

cd C:\path\to\Qt

configure -static <any other options you need

What I did:

cd C:\QtSDK (there is no C:\Qt)

configure -static
Output:

'configure' is not recognized as an internal or external command, operable program or batch file.


END OF ATTEMPT

TUTORIAL 3:
URL: qtnode.net/wiki?title-Building_static

1. To use static linking, you must first rebuild Qt to enable static linking.
2. To build a static app, use CONFIG += static inside your project (.pro) file.

Opened proejct in Qt Creator.

Double-clicked RPC.pro (my project filename)

Added CONFIG += static.

Saved.

Still received dll error.
3. To build a static lib that uses qt, use CONFIG += staticlib inside your project (.pro) file.

Added CONFIG += staticlib to RPC.pro

Still received dll error.
4. You may have to build the Qt library itself to be able to link Qt statically to your application. Before you compile Qt, when configure, use the -static option to enable static builds:

prompt> configure -static [other configure options]

Still not certain where to run this command.

End of attempt.

Pyrrha
13th August 2011, 15:22
Well I've successfully created a standalone executable. Here's how I got there.

I was unable to accomplish this with the QtSDK 4.7.3 setup I had. Instead, I uninstalled it, and installed an older version of QtSDK (2009.05) found here (ftp://ftp.qt.nokia.com/qtsdk/).

I attempted to run the usual configure -static and mingw32-make, but I received errors in the console as well as during attempts to compile my project afterwards.

Then I found this (http://qt-devnotes.blogspot.com/2010/01/qt-46-200905-fails-to-build-static.html) page and tried running those commands. I didn't get any errors, and my project compiled successfully, but running the executable still caused it to complain of a missing mingwm10.dll.

Then I found this (http://www.lemon-factory.com/2007/07/09/qt-430-static-and-no-mingwm10dll/) page, and tried mixing those commands with the previous ones. This succeeded, and allowed me to build my standalone executable.

In summary, this is what worked (succeeded in both Windows Vista Home Premium 64-bit and Windows 7 Professional 64-bit):

1. Install QtSDK (2009.05)

2. Open your mkspecswin32-g++qmake.conf file (located in C:\Qt\2009.05\qt\mkspecs\win32-g++\qmake.conf) in an editor like notepad.

3. Find the line that starts with "QMAKE_LFLAGS = -enable-stdcall-fixup..." and ddd the phrase "-static" (without quotes) after the "=" sign and before the "-enable..." phrase, so it looks like:
QMAKE_LFLAGS = -static -enable-stdcall...

4. Save and close this file.

5. Set your environment variables. Right-click Computer >> Properties >> Advanced System Settings >> Click the "Environment Variables..." button.

6. Under "User variables," make sure QTDIR is set to your Qt path (C:\Qt\2009.05\qt). Make sure QMAKESPEC is set to win32-g++.

7. Under "System variables," edit the one called "Path." Add a semicolon ( ; ) to the end, and add the following:
C:\Qt\2009.05\mingw\lib;C:\Qt\2009.05\mingw\bin;C: \Qt\2009.05\qt\bin

8. When finished, relog or reboot.

9. Open a command prompt.

10. Change to your Qt directory by entering: cd C:\Qt\2009.05\qt

11. Enter the following: configure -static -no-phonon -no-phonon-backend -release -no-exceptions

12. When it asks which edition you want to use, enter "o" for open source.

13. When it asks you to accept the terms of the license, enter "y" for yes. This will take around maybe 10 minutes to complete.

14. When that finishes, enter the following: mingw32-make sub-src

15. Go out to dinner, this will take a while (took between 1-2 hours for me).

16. When this finishes, open your project in the Qt Creator.

17. Double-click the project (.pro) file to open it in edit mode.

18. Add the following line: CONFIG += static

19. Change your build target to release mode.

20. Build your project.

21. Navigate to your release directory and voila! Your standalone executable should be there.

*NOTE: Some stuff doesn't work with static linking, like plugins, so you can't use static linking for everything.

marcvanriet
14th August 2011, 01:08
Nice work.

On a different computer, I think you still have to put mingwm10.dll in the path of your exe though.

Just one side remark : there are some licensing restrictons when you build Qt statically. See this post (http://www.qtcentre.org/threads/37806-Static-linking-against-Qt-4.7.1-with-microsoft-compiler-linker.?p=173819#post173819) for more info.

Regards,
Marc

jacks916
17th August 2011, 21:24
If you just want to send an excutable around, using something simple like: http://www.jrsoftware.org/isinfo.php
just point the outputted binaries (.dlls or .lib files) and this will pack them up in to an installer.

Gokulnathvc
18th August 2011, 08:44
I have followed your steps and i got following errors:


c:\Qt\2010.03\qt\lib/libQtGui.a(qapplication.o):qapplication.cpp:(.text +0x358a): undefined reference to `_imp___Z21qt_call_post_routinesv'
c:\Qt\2010.03\qt\lib/libQtGui.a(qapplication.o):qapplication.cpp:(.text +0x3b2f): undefined reference to `_imp___Z21qt_call_post_routinesv'
c:\Qt\2010.03\qt\lib/libQtGui.a(qapplication.o):qapplication.cpp:(.text +0x40ca): undefined reference to `_imp___Z21qt_call_post_routinesv'
c:\Qt\2010.03\qt\lib/libQtGui.a(qwhatsthis.o):qwhatsthis.cpp:(.text+0x1 5c): undefined reference to `_imp___Z21qDeleteInEventHandlerP7QObject'
collect2: ld returned 1 exit status
g++: unrecognized option '-static-enable-stdcall-fixup'
mingw32-make[1]: *** [release\ProgressControl.exe] Error 1
mingw32-make: *** [release] Error 2

Please help me

Pyrrha
19th August 2011, 00:15
Not sure how much help I can be since I Forrest-Gump'ed my way through this, but I did receive that same error many times in earlier failed attempts. I can't remember which step resolved it, or if it was changing to version 2009.05 that got rid of it. All I can say is this is what worked for me, and I wrote each step down as I completed it when I repeated the entire process on a separate computer. Good luck, and please do post if you find a solution!

vicbr
19th August 2011, 00:23
Another option: go to http://qt.nokia.com/downloads and download the last version of qt sdk and the last version of the qt libraries for mingw. Install the sdk first. Second install the qt libraries, it will ask for mingw, you can use the one in the sdk folder or you can download it here (http://www.mingw.org/).

Now go to START, QT by nokia and run Qt command prompt. The prompt already points to the qt directory. You should now run:


configure -static
make sub-src

It will take a while to compile. After is done you can use the prompt to cd to your project directory (to go updir use cd ..) and run:


make clean
qmake -config release
make

Don't forget the config += static in the pro file.

Added after 8 minutes:

If you want to compile dynamically, just use Qt creator. Make sure you set the buid configuration to release in the project tab and hit ctrl-r.

Once is done go the compiled folder and run the app. It will say ask for several libs.
Go to the Qt sdk folder, search then and put then in the compiled folder. It sould work now.