-   Programming (
-   -   Cross compilation (QT libraries) using gcc for Windows (

arunak 04-02-2007 12:44 AM

Cross compilation (QT libraries) using gcc for Windows
Hi all,

I am currently developing an application using QT libraries using Designer (That basically aids in the GUI development).

My System Specifications:

Ubuntu 6.10
Pentium 4, 3 GHz
512 MB RAM

I want to make this application work on all linux variants, Windows, and possibly unix (not that important). Can someone tell me what exactly needs to be done.

Also I need some idea about what static library compilation is. If the code is statically compiled, will the executable require the libraries to be installed on the host operating system?

Basically I need to know how to produce executables for other platforms with the source code that I have with as less tweaking on the other platform as possible.

Please do help me.

Thanks in advance.


gnashley 04-03-2007 01:40 PM

Sounds like a pretty stiff learning curve, actually. Try studying the source code for a fairly simple qt application which is available for the various platforms you want to support. Statically compiling means that the needed libraries are included in your binary and don't need to be installed on the host computre separately. In the case of using qt libs this way, you'd have very large slow binaries I think.

ta0kira 04-03-2007 05:20 PM

I think that might be a violation of the Qt license. Qt applications may be developed and distributed for GNU Qt for free, however to distribute applications that link to Windows Qt you need a commercial license (although cross-compiled GNU might be different.) If I remember correctly it is a few thousand US$. That's why some refer to Qt as a "commercial library" and why I would prefer to use GTK.

Maybe static linking isn't covered? Might have to distro the ENTIRE Qt package along with it which would be HUGE. I'd read the license very carefully. It would also require a static link to glibc and the gcc libstdc++, etc.

MinGW provides access to the Windows API. What I would do is design 100% portable internals and have specific interface points to a GUI and threads, etc., which can be designed specifically for Windows and Unix separately and linked in as appropriate. That is a good idea regardless of if you support multiple OSes because you may decide Qt isn't what you want, or Qt might not be free in the future.

Mega Man X 04-03-2007 06:34 PM

I think the Qt license has changed since last year and it no longer requires a $$$ license for Windows. I just quickly looked into their page but did not find anything (though, I really did not browse longer than 10 seconds there). This is also one of the reasons that KDE and Konqueror are being ported to Windows...

ta0kira 04-03-2007 07:42 PM

Looks like you are right:

Also says it will support MinGW which is very useful. I think porting KDE to Windows is a way up for Linux because rather than pulling potential users from their comfort zone it can teach them an interface they can also use with Linux. Well, depending on HOW KDE is ported.

arunak 04-04-2007 12:43 AM

Thanks a lot for the replies...

So qt/windows version is also free (to some extent - whatever that means).
Can someone help me how to produce executables for windows, other linux variants.

I tried compiling the application in my system and tried to run on a different system (presumably the kernel was older than that of mine), it wouldn't run. It said some floating point exception.
Also I want to enable users use my application without really installing QT in their system. So static compilation is the only option i have got.

So I need two things:
1) Compiling the qt project statically.
2) remove the platform dependency (i386 is enuf, but OS is optional) and produced a generalized binary or atleast produce a list of few binaries, so that the appropriate binary could be chosen.

I don't know how "noob" i sounded when I tried to say what I wanted. Please excuse me for the same. I am really a newbie.

Thanks again in advance. :-)

graemef 04-04-2007 04:27 AM

If you want it to run on windows then you need to compile it under windows.

The community version of QT is the same as the community version for Linux. It is limited to the type of compiler that it can be compiled with which is essentially the MinGW compiler - which you get if you download DevC++.

From what I recall you don't need to statically link the program, but you can include the libraries with the distribution. For Windows that will be the dll that comes with the windows distribution.

arunak 04-04-2007 11:23 PM

I guess including librarires and properly linking it to the object code of the library could be very painful...

Just as a curiosity i wanted to know if i can statically link qt librarires to my binary..
I tried changing the makefile for an application by putting -static switch for linking. It didn't work. Can someone help me to sort the problem out?

akarun@ubuntu:~/Sharescan$ make
/usr/share/qt3/bin/uic sharescan.ui -o .ui/sharescan.h
g++ -c -pipe -Wall -W -O2 -D_REENTRANT -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/share/qt3/mkspecs/default -I. -I/usr/include/qt3 -I.ui/ -I. -I.moc/ -o .obj/main.o main.cpp
/usr/share/qt3/bin/uic sharescan.ui -i sharescan.h -o .ui/sharescan.cpp
g++ -c -pipe -Wall -W -O2 -D_REENTRANT -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/share/qt3/mkspecs/default -I. -I/usr/include/qt3 -I.ui/ -I. -I.moc/ -o .obj/sharescan.o .ui/sharescan.cpp
/usr/share/qt3/bin/moc .ui/sharescan.h -o .moc/moc_sharescan.cpp
g++ -c -pipe -Wall -W -O2 -D_REENTRANT -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/share/qt3/mkspecs/default -I. -I/usr/include/qt3 -I.ui/ -I. -I.moc/ -o .obj/moc_sharescan.o .moc/moc_sharescan.cpp
g++ -static -o Sharescan .obj/main.o .obj/sharescan.o .obj/moc_sharescan.o -L/usr/share/qt3/lib -L/usr/X11R6/lib -lqt-mt -lXext -lX11 -lm -lpthread
/usr/bin/ld: cannot find -lqt-mt
collect2: ld returned 1 exit status
make: *** [Sharescan] Error 1

PS: I am sorry if everything looks cluttered.. :P

arunak 04-04-2007 11:25 PM

And ofcourse if i remove -lqt-mt switch from the linking step... things dont compile due to undefined references.

tread 04-04-2007 11:54 PM

The free qt for windows is available here:
As someone said, use MinGW. There are instructions to compile it for windows using MinGW, I have done this successfully before.

Linking statically to remove dependencies should work as long as you use only qt libraries - if you use kde libs you may not be able to do that. E.g., opera links qt statically for linux systems.

graemef 04-05-2007 12:39 AM

My first observation is that the community version of QT for Windows is QT4, so you would do well to port your application from QT3 to QT4.

Once you have installed QT4 you can check out the documentation (search for: "static linking") and you'll find an example stepping you through the process of linking static libraries.

QT4 documentation also has a good section on deploying applications.

I hope that helps you.


graemef 04-05-2007 01:51 AM


Originally Posted by tread
The free qt for windows is available here

Oh a port of qt3 for windows... learn something new each day... whilst it's not clear on their site I doubt that that this could be used for the creation of commercial products. Give Qt's licencing rules.

tread 04-05-2007 01:59 AM


Originally Posted by graemef
Oh a port of qt3 for windows... learn something new each day... whilst it's not clear on their site I doubt that that this could be used for the creation of commercial products. Give Qt's licencing rules.

From their page:
# Complete gpl licensed replacement for win32 environments
# based on the gpl'ed Qt/x11 sources means there is no licensing problems with any commercial trolltech license

gnashley 04-05-2007 03:02 AM

The OP doesn't say whether he intends the software to be commercial or not, so maybe the licensing is not an issue anyway.
As for compiling with MingW, if it's possible to do that under Windows, he should be able to use ix86-MingW32 under Ubuntu to compile the binaries for W32 architecture.
If there aren't packages for Ubuntu for the ix86-MingW32 compiler, headers and runtime libs he could use one from Debian -I know there are 'unofficial' debs for them.
Or you can get a (mega) package I made for Slackware here:

ta0kira 04-05-2007 12:16 PM


Originally Posted by arunak
And ofcourse if i remove -lqt-mt switch from the linking step... things dont compile due to undefined references.

That's because you have Qt compiled for multithreading so without that switch it looks for non-multithreaded libs.

To generate object code and then link on the target machine you will need an incremental link with the gcc libs. This is because compilation of C++ with gcc causes link dependencies with its own libs and object files.

To force static linkage, list the .a libs directly on the ld command line before any other libs. That way it will find the correct definition in a static lib before it finds it in a shared lib. Also, I don't know if Qt even compiles static libs by default. That could be the problem. If it only generates shared libs then you will not be able to statically link. You could hack a static lib of your own, but that would make it a reimplementation of Qt.

All times are GMT -5. The time now is 01:35 PM.