PDA

View Full Version : making a portable binary on windows



patcito
25th May 2006, 15:15
hey all,
I have my application up and running ok. The only problem is that when I execute the .exe on another machine it doesn't work unless I install Qt4+MinGW. So my question is how can I compile my Qt app so that it contains the necessary Qt and MinGW dlls or is there are there tutorials I missed online?

thanx in advance

Pat

munna
25th May 2006, 15:46
Why dont you ship Qt 4 + minGW dlls along with your exe ?

jacek
25th May 2006, 15:48
Dependency Walker (http://www.dependencywalker.com) will tell you what DLLs are required by your application. Just copy proper Qt DLLs and mingw10.dll to the same directory where your executable is and everything should work. If you use Qt plugins, you will have to copy them to proper subdirectories.

michael
25th May 2006, 15:50
When you compile a program with Qt and basically any compiler your program will be dependent on some dlls provided by Qt and the compiler.

For example if you compile a very basic Qt Application that only has a main window and pop up screen with mingw32-gcc-3.4.2 and Qt 4.x.x you would need to distribute the following dlls with your application for it to work on another computer.

I think this is all of them you would need. You might also need another microsoft dll as well. It has been a while since I compiled a program for another comptuer with mingw. But this should give you the basic idea.

mingwm10.dll
QtCore4.dll
QtGui4.dll

For example if I compile with Visual Studio 2005 instead of mingw I might need to distrubute msvcp80.dll with my application instead of mingwm10.dll.

You can use depends.exe to see all of the DLLs your program needs to run. The program can be found here: http://www.dependencywalker.com/

Note that it will show a large list. Most of the DLLs will already be on the target system as they are a part of windows. You will simply need to look for the Qt DLLs and the mingwm10 one. If you forget one when you try running the program on a target machine it should tell you which DLL it can not find.

Also if you never plan on having any kind of plugins or anything for your program you can rebuild Qt in static mode. This will compile everything into the executable (Qt speaking). You will still need to include the DLL from your compiler, however, you will not need to distribute the Qt DLLs as well.

I hope this helps you.

jcr
25th May 2006, 18:07
Can the compiler library (mingwm10.dll, msvcp80.dll..) be compiled statically as well?Maybe it is not a good idea?

patrik08
26th May 2006, 11:52
I have write this question on mingw forum...
The answer....

>>>>
You should search the mailing list archives as this is asked every 6 months or so.

The answer is that any multi-threaded C++ app that uses exceptions must be compiled with -mthreads, and enabling this switch adds a dependency on mingwm10.dll and there is absolutely no way around that. It cannot be made static, due to how it works. If you make your app single-threaded and/or you disable exceptions (-fno-exceptions) then you could probably get away without needing -mthreads.
<<<<<

Now my question how disable -mthreads on pro file QMAKE_LFLAGS ??

jacek
26th May 2006, 11:57
Now my question how disable -mthreads on pro file QMAKE_LFLAGS ??
You could just set a new value for this variable, but AFAIK you can't compile Qt 4 without it.

rickbsgu
27th May 2006, 22:11
You used to be able to configure Qt to build static libs. I presume you can still do that.(? - I'm not at a machine I can check...)

If you can get the mingw source and build configuration, you should be able to create static mingw libs.

Threads don't matter whether static or dll, as far as I know.

Ditto for any other third party libs.

You're definitely probing outside the box, it will require you to do a lot of building on your own, but it should be possible. Whether it's worthwhile vs. just distributing the .dlls or not is another question. It can be a lot of work.

rickb

patrik08
27th May 2006, 22:21
<<<If you can get the mingw source and build configuration, you should be able to create static mingw libs.>>>>

Yes i can build libs but the code from mingw is so large....... wahts file take????


OK MingW impossibel!.....

You think Borland Compiler is Better to make portable exe .....? or Other Window compiler....

rickbsgu
28th May 2006, 02:35
<<<If you can get the mingw source and build configuration, you should be able to create static mingw libs.>>>>

Yes i can build libs but the code from mingw is so large....... wahts file take????


OK MingW impossibel!.....

It would be a matter of reconfiguring the make file/project to create static libs. They might provide a configuration to do that. I haven't gotten into mingw, so can't tell you.



You think Borland Compiler is Better to make portable exe .....? or Other Window compiler....
Not sure what you mean by 'portable'. If the systems are configured identically, one exe should work on all, but you may have to pull over the extra pieces, like dlls, etc., if the .exe is not fully resolved on its own.

Back in the old days, we used to have hot debates about Borland vs. Microsoft. In the end, we wound up with the Microsoft compiler, because we knew that's what the OS was built with, what Windows was built with, and we wouldn't have any compatibility issues, especially with kits like MFC. And MS was naturally ahead of the curve on anything Windows.

Since you're using mingw, it shouldn't matter, frankly. (I presume you're not using the cygwin mingw, which brings in whole other issues.)

I'm using the MS compiler, because I still have to use MS toolkits.

rickb

jpn
29th May 2006, 10:02
Give this a try:
Qt4 with Visual Studio and static C runtime (http://qtnode.net/wiki/Qt4_with_Visual_Studio_and_static_C_runtime)

PS. There's a free version of VS2005 (express) out there..