PDA

View Full Version : Program runs from Creator, but not as a standalone?



N3wb
30th September 2012, 18:21
My program runs fine from Qt Creator, but I cannot run it as a standalone program.

I was receiving an error about .dll's not being found, so I copied libgcc_s_dw2-1.dll and mingwm10.dll to my .exe's folder, and now I'm receiving this error:


The application was unable to start correctly (0xc000007b). Click OK to close the application

What do I need to do to be able to run the .exe outside of Qt?

Lesiok
30th September 2012, 18:25
RTFM (read this fine manual) : deploying Qt applications (http://doc.qt.digia.com/4.7-snapshot/deployment.html)

N3wb
30th September 2012, 18:39
Hi,

Thanks for your help.

I'm still really confused what I need to do. I tried copying all the dll's from \Qt\Desktop\Qt\4.8.1\mingw\bin to my .exe's folder, but it still doesn't run.

amleto
30th September 2012, 22:11
did you read it?

Thuthuka
1st October 2012, 10:46
Hi

You reference .dll's so I assume you are using windows.
So take a look here.
http://support.microsoft.com/kb/198038/en-us

Get the depends.exe application "its free" and do a dependency check
to see which .dll's your application is using and needs and only copy those.

Also check how you are building your application. Are you copying over
the release build and not the debug build?

N3wb
8th October 2012, 04:06
I can't get the shared libraries method to work, so I'm trying to build my application statically (which I guess I would prefer anyway..), but I'm having trouble with the instructions:


Building Qt Statically

Before we can build our application we must make sure that Qt is built statically. To do this, go to a command prompt and type the following:

cd C:\path\to\Qt
configure -static <any other options you need>

By "C:\path\to\Qt" I'm assuming it means "E:\Qt\Desktop\Qt\4.8.0\mingw," right?

As recommended in this article (http://qt-project.org/wiki/Build_Standalone_Qt_Application_for_Windows), I tried executing the command:


configure -static -release -no-exceptions

But that prints out errors:



E:\Qt\Desktop\Qt\4.8.0\mingw>configure -static -release -no-exceptions
Unable to detect the platform from environment. Use -platform command lineargume
nt or set the QMAKESPEC environment variable and run configure again
See the README file for a list of supported operating systems and compilers.
Usage: configure [-buildkey <key>]
[-release] [-debug] [-debug-and-release] [-shared] [-static]
[-no-fast] [-fast] [-no-exceptions] [-exceptions]
[-no-accessibility] [-accessibility] [-no-rtti] [-rtti]
[-no-stl] [-stl] [-no-sql-<driver>] [-qt-sql-<driver>]
[-plugin-sql-<driver>] [-system-sqlite] [-arch <arch>]
[-D <define>] [-I <includepath>] [-L <librarypath>]
[-help] [-no-dsp] [-dsp] [-no-vcproj] [-vcproj]
[-no-qmake] [-qmake] [-dont-process] [-process]
[-no-style-<style>] [-qt-style-<style>] [-redo]
[-saveconfig <config>] [-loadconfig <config>]
[-qt-zlib] [-system-zlib] [-no-gif] [-no-libpng]
[-qt-libpng] [-system-libpng] [-no-libtiff] [-qt-libtiff]
[-system-libtiff] [-no-libjpeg] [-qt-libjpeg] [-system-libjpeg]
[-no-libmng] [-qt-libmng] [-system-libmng] [-no-qt3support] [-mmx]
[-no-mmx] [-3dnow] [-no-3dnow] [-sse] [-no-sse] [-sse2] [-no-sse2]
[-no-iwmmxt] [-iwmmxt] [-openssl] [-openssl-linked]
[-no-openssl] [-no-dbus] [-dbus] [-dbus-linked] [-platform <spec>]
[-qtnamespace <namespace>] [-qtlibinfix <infix>] [-no-phonon]
[-phonon] [-no-phonon-backend] [-phonon-backend]
[-no-multimedia] [-multimedia] [-no-audio-backend] [-audio-backend]
[-no-script] [-script] [-no-scripttools] [-scripttools]
[-no-webkit] [-webkit] [-webkit-debug]
[-graphicssystem raster|opengl|openvg]
[-no-directwrite] [-directwrite]

Installation options:

You may use these options to turn on strict plugin loading:

-buildkey <key> .... Build the Qt library and plugins using the specified
<key>. When the library loads plugins, it will only
load those that have a matching <key>.

Configure options:

The defaults (*) are usually acceptable. A plus (+) denotes a default value
that needs to be evaluated. If the evaluation succeeds, the feature is
included. Here is a short explanation of each option:

* -release ........... Compile and link Qt with debugging turned off.
-debug ............. Compile and link Qt with debugging turned on.
-debug-and-release . Compile and link two Qt libraries, with and without
debugging turned on.

-opensource ........ Compile and link the Open-Source Edition of Qt.
-commercial ........ Compile and link the Commercial Edition of Qt.

-developer-build ... Compile and link Qt with Qt developer options
(including auto-tests exporting)

-shared ............ Create and use shared Qt libraries.
* -static ............ Create and use static Qt libraries.

-ltcg .............. Use Link Time Code Generation. (Release builds only)
* -no-ltcg ........... Do not use Link Time Code Generation.

* -no-fast ........... Configure Qt normally by generating Makefiles for all
project files.
-fast .............. Configure Qt quickly by generating Makefiles only for
library and subdirectory targets. All other Makefiles
are created as wrappers which will in turn run qmake

* -no-exceptions ..... Disable exceptions on platforms that support it.
-exceptions ........ Enable exceptions on platforms that support it.

-no-accessibility .. Do not compile Windows Active Accessibility support.
* -accessibility ..... Compile Windows Active Accessibility support.

-no-stl ............ Do not compile STL support.
* -stl ............... Compile STL support.

-no-sql-<driver> ... Disable SQL <driver> entirely, by default none are
turned on.
-qt-sql-<driver> ... Enable a SQL <driver> in the Qt Library.
-plugin-sql-<driver> Enable SQL <driver> as a plugin to be linked to at run
time.
Available values for <driver>:
mysql
psql
oci
odbc
tds
db2
+ sqlite
sqlite2
ibase
(drivers marked with a '+' have been detected as
available on this system)

-system-sqlite ..... Use sqlite from the operating system.

-no-qt3support ..... Disables the Qt 3 support functionality.

-no-opengl ......... Disables OpenGL functionality

-opengl <api> ...... Enable OpenGL support with specified API version.
Available values for <api>:
* desktop - Enable support for Desktop OpenGL
es1 - Enable support for OpenGL ES Common Profile
es2 - Enable support for OpenGL ES 2.0
* -no-openvg ......... Disables OpenVG functionality

-openvg ............ Enables OpenVG functionality
Requires EGL support, typically supplied by an OpenGL
or other graphics implementation

-platform <spec> ... The operating system and compiler you are building on.
(default %QMAKESPEC%)

-xplatform <spec> .. The operating system and compiler you are cross
compiling to.

See the README file for a list of supported operating
systems and compilers.

-qtnamespace <namespace> Wraps all Qt library code in 'namespace name {...}
-qtlibinfix <infix> Renames all Qt* libs to Qt*<infix>

-D <define> ........ Add an explicit define to the preprocessor.
-I <includepath> ... Add an explicit include path.
-L <librarypath> ... Add an explicit library path.
-l <libraryname> ... Add an explicit library name, residing in a
librarypath.

-graphicssystem <sys> Specify which graphicssystem should be used.
Available values for <sys>:
* raster - Software rasterizer
opengl - Using OpenGL acceleration, experimental!
openvg - Using OpenVG acceleration, experimental!

-help, -h, -? ...... Display this information.

Third Party Libraries:

-qt-zlib ........... Use the zlib bundled with Qt.
+ -system-zlib ....... Use zlib from the operating system.
See http://www.gzip.org/zlib

-no-gif ............ Do not compile GIF reading support.
-no-libpng ......... Do not compile PNG support.
-qt-libpng ......... Use the libpng bundled with Qt.
+ -system-libpng ..... Use libpng from the operating system.
See http://www.libpng.org/pub/png

-no-libmng ......... Do not compile MNG support.
-qt-libmng ......... Use the libmng bundled with Qt.
+ -system-libmng ..... Use libmng from the operating system.
See See http://www.libmng.com

-no-libtiff ........ Do not compile TIFF support.
-qt-libtiff ........ Use the libtiff bundled with Qt.
+ -system-libtiff .... Use libtiff from the operating system.
See http://www.libtiff.org

-no-libjpeg ........ Do not compile JPEG support.
-qt-libjpeg ........ Use the libjpeg bundled with Qt.
+ -system-libjpeg .... Use libjpeg from the operating system.
See http://www.ijg.org


Output continued..........




Qt for Windows only:

-no-dsp ............ Do not generate VC++ .dsp files.
* -dsp ............... Generate VC++ .dsp files, only if spec "win32-msvc".

-no-vcproj ......... Do not generate VC++ .vcproj files.
* -vcproj ............ Generate VC++ .vcproj files, only if platform
"win32-msvc.net".

-no-incredibuild-xge Do not add IncrediBuild XGE distribution commands to
custom build steps.
+ -incredibuild-xge .. Add IncrediBuild XGE distribution commands to custom
build steps. This will distribute MOC and UIC steps,
and other custom buildsteps which are added to the
INCREDIBUILD_XGE variable.
(The IncrediBuild distribution commands are only added
to Visual Studio projects)

-no-plugin-manifests Do not embed manifests in plugins.
* -plugin-manifests .. Embed manifests in plugins.

-no-qmake .......... Do not compile qmake.
* -qmake ............. Compile qmake.

-dont-process ...... Do not generate Makefiles/Project files. This will
override -no-fast if specified.
* -process ........... Generate Makefiles/Project files.

-no-rtti ........... Do not compile runtime type information.
* -rtti .............. Compile runtime type information.

-no-mmx ............ Do not compile with use of MMX instructions
+ -mmx ............... Compile with use of MMX instructions
-no-3dnow .......... Do not compile with use of 3DNOW instructions
+ -3dnow ............. Compile with use of 3DNOW instructions
-no-sse ............ Do not compile with use of SSE instructions
+ -sse ............... Compile with use of SSE instructions
-no-sse2 ........... Do not compile with use of SSE2 instructions
+ -sse2 .............. Compile with use of SSE2 instructions
-no-openssl ........ Do not compile in OpenSSL support
+ -openssl ........... Compile in run-time OpenSSL support
-openssl-linked .... Compile in linked OpenSSL support
-no-dbus ........... Do not compile in D-Bus support
+ -dbus .............. Compile in D-Bus support and load libdbus-1 dynamicall
y
-dbus-linked ....... Compile in D-Bus support and link to libdbus-1
-no-phonon ......... Do not compile in the Phonon module
+ -phonon ............ Compile the Phonon module (Phonon is built if a decent
C++ compiler is used.)
-no-phonon-backend . Do not compile the platform-specific Phonon backend-pl
ugin
* -phonon-backend .... Compile in the platform-specific Phonon backend-plugin
-no-multimedia ..... Do not compile the multimedia module
* -multimedia ........ Compile in multimedia module
-no-audio-backend .. Do not compile in the platform audio backend into QtMu
ltimedia
+ -audio-backend ..... Compile in the platform audio backend into QtMultimedi
a
-no-webkit ......... Do not compile in the WebKit module
+ -webkit ............ Compile in the WebKit module (WebKit is built if a
decent C++ compiler is used.)
-webkit-debug ...... Compile in the WebKit module with debug symbols.
-no-script ......... Do not build the QtScript module.
+ -script ............ Build the QtScript module.
-no-scripttools .... Do not build the QtScriptTools module.
+ -scripttools ....... Build the QtScriptTools module.
-no-declarative .... Do not build the declarative module
+ -declarative ....... Build the declarative module
-no-declarative-debug Do not build the declarative debugging support
* -declarative-debug . Build the declarative debugging support
* -no-directwrite .... Do not build support for DirectWrite font rendering
-directwrite ....... Build support for DirectWrite font rendering
(experimental, requires DirectWrite availability on
target systems, e.g. Windows Vista with Platform
Update, Windows 7, etc.)
-arch <arch> ....... Specify an architecture.
Available values for <arch>:
* windows
windowsce
symbian
boundschecker
generic

-no-style-<style> .. Disable <style> entirely.
-qt-style-<style> .. Enable <style> in the Qt Library.
Available styles:
* windows
+ windowsxp
+ windowsvista
* plastique
* cleanlooks
* motif
* cde
windowsce
windowsmobile
s60

-no-native-gestures Do not use native gestures on Windows 7.
* -native-gestures ... Use native gestures on Windows 7.
* -no-mp ............. Do not use multiple processors for compiling with MSVC
-mp ................ Use multiple processors for compiling with MSVC (-MP)
-loadconfig <config> Run configure with the parameters from file configure_
<config>.cache.
-saveconfig <config> Run configure and save the parameters in file
configure_<config>.cache.
-redo .............. Run configure with the same parameters as last time.

Qt for Windows CE only:

-no-iwmmxt ......... Do not compile with use of IWMMXT instructions
+ -iwmmxt ............ Do compile with use of IWMMXT instructions (Qt for
Windows CE on Arm only)
* -no-crt ............ Do not add the C runtime to default deployment rules
-qt-crt ............ Qt identifies C runtime during project generation
-crt <path> ........ Specify path to C runtime used for project generation.
-no-cetest ......... Do not compile Windows CE remote test application
+ -cetest ............ Compile Windows CE remote test application
-signature <file> .. Use file for signing the target project
* -phonon-wince-ds9 .. Enable Phonon Direct Show 9 backend for Windows CE
Qt for Symbian OS only:

* -no-freetype ....... Do not compile in Freetype2 support.
-qt-freetype ....... Use the libfreetype bundled with Qt.
-fpu <flags> ....... VFP type on ARM, supported options: softvfp(default) |
vfpv2 | softvfp+vfpv2
-no-s60 ............ Do not compile in S60 support.
* -s60 ............... Compile with support for the S60 UI Framework
-no-usedeffiles .... Disable the usage of DEF files.
-usedeffiles ....... Enable the usage of DEF files.

Added after 7 minutes:

As a follow up comment to all this, I really don't understand why this is made so difficult. Why isn't there a button in Qt Creator that just says "Build Standalone" or something and that does all this automatically?!

Added after 22 minutes:

As the title of this thread and it's contents are no longer representative of my problem (trying to build Qt statically) I am going to create a new thread with that subject.

Please consider this thread CLOSED.

ChrisW67
8th October 2012, 04:25
C:\path\to\Qt is the path to your copy of the Qt source code. You are reading instructions on how to build static Qt libraries from source.

I do not know why so many new Qt users think that things will be easier without those pesky DLLs. It really is quite simple and has been covered here many times. Here is an example layout (http://www.qtcentre.org/threads/46927-Location-of-imageformats-directory?p=211945#post211945) for the Qt components, to which you must add any compiler runtime components you need. The image format/sql/other plugins you deploy depend on what your program needs.

When you still cannot make it fly Dependency Walker (http://www.dependencywalker.com/) is your friend.

N3wb
8th October 2012, 04:41
C:\path\to\Qt is the path to your copy of the Qt source code. You are reading instructions on how to build static Qt libraries from source.

I installed the entire SDK. Are you saying I don't have the "source code"?



I do not know why so many new Qt users think that things will be easier without those pesky DLLs.

Because I literally tried copying every DLL I saw in the Qt folders to my application folder and it still would not run.

While it's true that I haven't spent a ton of time trying to understand this problem, I have spent several hours trying to get this to work, and building an application stand alone SHOULD NOT BE THIS HARD. I can not understand why Nokia would go through so much trouble developing an incredibly easy to use IDE (Creator) but not make an easy way to deploy the application. I just don't get it. And I'm not alone in this; searching Google shows hundreds, if not thousands, of threads/blogposts/email lists where people are begging for help trying to figure out how the hell they can deploy their application. I've probably spent more time trying to deploy my application then I did programming it. That's stupid.

Anyways, I tried running Dependency Walker and it just spat out a ton of errors.

ChrisW67
8th October 2012, 05:49
I installed the entire SDK. Are you saying I don't have the "source code"?
Define "entire". The default SDK installation does not include source, only binaries, although source is available through the SDK updater. Source files are installed into the obscurely named "{QtSdk}\QtSources\{x.y.z}" folders. Source can also be retrieved the Qt project web site.


Because I literally tried copying every DLL I saw in the Qt folders to my application folder and it still would not run.
The action you just described is one of desperation not analytical problem solving. Did you stop to understand how Windows loads dynamic libraries (http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586%28v=vs.85%29.aspx) (nothing to do with Qt BTW)? Or what your program actually requires to run? Or what the Qt deployment instructions are telling you? Or what Dependency Walker is telling you? It is not that hard, but there is no generic Make-a-magic-bundle button because every application is different. Incidentally, Nokia did produce a deploy function for the controlled environment of their phone platforms.

Dependency Walker highlights in red items that the program needs to have a hope of starting. You can safely ignore "WER.DLL" and "IESHIMS.DLL", everything else needs to be investigated. The name of the file it expected to load is there to see.


Here is the TL;DR version: A Qt program requires four things to run;

The program executable built with {compiler} using Qt version {x.y.z}. Easily found by most. Should go into your program deployment folder.
The C/C++ runtime matching {compiler}. mingwm10.dll and libgcc_s_dw2-1.dll in the case of MingW or the Microsoft equivalent. Should go into your program deployment folder (MingW), or needs to be installed (Microsoft). MingW file can be found the same place as the Qt libs below. Microsoft's runtime is part of Visual Studio or can be downloaded.
The Qt dynamic libraries for the modules used. This item is satisfied by the files from "{QtSdk}\Desktop\Qt\{x.y.z}\{compiler}\bin" folder. If your program is built in release mode you want QtCore4.dll, QtGui4.dll etc. For debug mode you want QtCore4d.dll, QtGui4d.dll etc. No point shipping debug libraries with a program linked to the release ones or vice versa. These files should go in your program deployment folder.
Any Qt plugins needed to support the program and any libraries they are dependent on. The absence of these is usually not fatal to launching the program but clearly cripples the function of the program. These files are found in "{QtSdk}\Desktop\Qt\{x.y.z}\{compiler}\plugins\{typ e}" folders and go into "{type}" sub-folders of your deployment folder. Often the SQL drivers need a client DLL from the database software and this goes here also.

The layout of a deployed application is per my earlier post. Try it first with a simple "Hello, World!" window application and build up from there.

wiseguy12851
8th October 2012, 09:20
I've spent weeks trying to get a program to work outside of qt Creator. Referenced thousands of people begging for help from all over the internet - If they got help it was ALWAYS the infamous deployment page time after time. The deployment page is extremely helpful and tells me a lot, but in the end I was still confused, despite this, me and anybody else with this issue was sent again and again to "The Deployment Page". The purpose of a forum is to get help from people who know what they're doing because the person him/herself cannot figure it out alone.


And I'm not alone in this; searching Google shows hundreds, if not thousands, of threads/blogposts/email lists where people are begging for help trying to figure out how the hell they can deploy their application.
I love that! That's my favorite phrase. It completely wraps up the issue us newcomers are having.

Finally ChrisW67 get's on and explains the "simple steps" that thousands of other developers have ignored and fought hard against not saying, simply redirecting to "The Deployment Page" when the reason we're on the forums is because we don't understand the page so we're just asking a human instead. I'm not saying the page isn't clear, I'm just saying, as a newcomer to Qt, I didn't understand it.


Here is the TL;DR version: A Qt program requires four things to run;

The program executable built with {compiler} using Qt version {x.y.z}. Easily found by most. Should go into your program deployment folder.
The C/C++ runtime matching {compiler}. mingwm10.dll and libgcc_s_dw2-1.dll in the case of MingW or the Microsoft equivalent. Should go into your program deployment folder (MingW), or needs to be installed (Microsoft). MingW file can be found the same place as the Qt libs below. Microsoft's runtime is part of Visual Studio or can be downloaded.
The Qt dynamic libraries for the modules used. This item is satisfied by the files from "{QtSdk}\Desktop\Qt\{x.y.z}\{compiler}\bin" folder. If your program is built in release mode you want QtCore4.dll, QtGui4.dll etc. For debug mode you want QtCore4d.dll, QtGui4d.dll etc. No point shipping debug libraries with a program linked to the release ones or vice versa. These files should go in your program deployment folder.
Any Qt plugins needed to support the program and any libraries they are dependent on. The absence of these is usually not fatal to launching the program but clearly cripples the function of the program. These files are found in "{QtSdk}\Desktop\Qt\{x.y.z}\{compiler}\plugins\{ty pe}" folders and go into "{type}" sub-folders of your deployment folder. Often the SQL drivers need a client DLL from the database software and this goes here also.

So that short paragraph answers the famous question, now my program works like a charm on it's on.

I understand that projects, build environments, and targets can get complicated so I understand why Qt can't have an easy button for this. But for simple projects and starter projects, this is all I was looking for, now if I get any more errors I have a pretty good idea what to do from here and how better to ask or look-up for help.

The only other question I have is how do I know when to use the other dll's such as QtHelp or QtScript and if I use custom css-like styling in my forms does that add a dll dependency.

N3wb
8th October 2012, 15:20
Thank you for all of your help ChrisW67. Sorry I got a bit frustrated :rolleyes: I'll take your advice, step back, and try this again more analytically.

wysota
8th October 2012, 23:07
I'm not saying the page isn't clear, I'm just saying, as a newcomer to Qt, I didn't understand it.
You see... the thing is your problem has nothing to do with Qt. It's a "problem" with any regular system application and if you consider yourself a developer, one day you will have to learn it. While Chris's post is undoubtly useful, it only covers one of the typical situations. Sooner or later you will want to use some third party (completely unrelated to Qt) library and that's where those instructions will fail you immediately and if you don't know the rules governing your platform, you'll be stuck forever. Many people would then come back here and claim that Chris's instructions were wrong because they didn't work for them. And then they'd be redirected to... surprise, surprise... "the deployment page" again or even to MSDN or Google for even more generic instructions. That's because magic-button solutions are good only for "hello world" complexity programs and for anything serious you'll have to get your hands dirty or just be left standing and scratching your head not knowing what to do next.


Like for your question about when to use a particular dll or does something add a dependency -- you'll either have to wait for the solution to fall on you from the sky or you'll knuckle down and look it up yourself.

ChrisW67
9th October 2012, 00:11
The only other question I have is how do I know when to use the other dll's such as QtHelp or QtScript and if I use custom css-like styling in my forms does that add a dll dependency.

You get a fairly strong clue from any module you added to the QT variable in your PRO file. In addition to the default "core" and "gui" if you add "network" you will be dependent on QtNetwork4.dll (or your platform's equivalent). Add "sql" -> QtSql4.dll, "svg" -> QtSvg4.dll etc. This covers the basic Qt application quite well.

If your program uses images in formats other than PNG then you will need an image format plugin or two. If your program uses SQL you will need an SQL plugin or two. If your program uses QtScript then you probably need the plugins to support that (never used it myself). If you use codecs then you might need codec plugins. Only you know what your code needs.

Other direct static dependencies you may miss will be identified by loading your executable into Dependency Walker (DW) or using ldd on Linux. If you use the Profile option in Dependency Walker it will execute your program and allow you to catch what it attempts to load dynamically. There is potentially a LOT of output, so you would do this as a last resort.

You can also load any of the Qt libraries into DW and see their direct dependencies. This tells you that QtHelp4.dll requires core, gui, network, and lucene at the least (and probably some of the image format and codec plugins would be used indirectly). QtScript only depends on core, but has a set of plugins that you may be using.

Of course, for dev/testing purposes you could just deploy all the Qt libraries and plugins and pare that down for release.