LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-02-2007, 01:44 AM   #1
arunak
LQ Newbie
 
Registered: Jan 2006
Posts: 9

Rep: Reputation: 0
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.

Arun
 
Old 04-03-2007, 02:40 PM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,771

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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.
 
Old 04-03-2007, 06:20 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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.
ta0kira
 
Old 04-03-2007, 07:34 PM   #4
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
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...
 
Old 04-03-2007, 08:42 PM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Looks like you are right:
http://www.trolltech.com/developer/downloads/qt/windows

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.
ta0kira
 
Old 04-04-2007, 01:43 AM   #6
arunak
LQ Newbie
 
Registered: Jan 2006
Posts: 9

Original Poster
Rep: Reputation: 0
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. :-)
 
Old 04-04-2007, 05:27 AM   #7
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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.

Last edited by graemef; 04-04-2007 at 09:08 AM.
 
Old 04-05-2007, 12:23 AM   #8
arunak
LQ Newbie
 
Registered: Jan 2006
Posts: 9

Original Poster
Rep: Reputation: 0
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
 
Old 04-05-2007, 12:25 AM   #9
arunak
LQ Newbie
 
Registered: Jan 2006
Posts: 9

Original Poster
Rep: Reputation: 0
And ofcourse if i remove -lqt-mt switch from the linking step... things dont compile due to undefined references.
 
Old 04-05-2007, 12:54 AM   #10
tread
LQ Newbie
 
Registered: Feb 2007
Posts: 29

Rep: Reputation: 15
The free qt for windows is available here: http://qtwin.sourceforge.net/qt3-win32/index.php
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.
 
Old 04-05-2007, 01:39 AM   #11
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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.

graeme.
 
Old 04-05-2007, 02:51 AM   #12
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
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.
 
Old 04-05-2007, 02:59 AM   #13
tread
LQ Newbie
 
Registered: Feb 2007
Posts: 29

Rep: Reputation: 15
Quote:
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
 
Old 04-05-2007, 04:02 AM   #14
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,771

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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:

http://distro.ibiblio.org/pub/linux/...4.5-i586-1.tgz
 
Old 04-05-2007, 01:16 PM   #15
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
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.
ta0kira
 
  


Reply

Tags
compilation, cross, gcc, libraries, qt, static


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
linking error during cross compilation with ucibc libraries raklo Linux - Kernel 0 03-26-2007 12:48 AM
Cross compiling to Windows binary, including Linux shared libraries Siiiiiii Programming 2 03-09-2007 01:36 AM
gcc c cross compiler to create linux executables on a windows system Wanda Tinasky Programming 1 02-25-2007 10:36 AM
cross compilation NeoMagic Programming 5 12-13-2006 03:19 AM
Cross-compilation radhapriya Linux - Software 0 08-11-2003 08:24 AM


All times are GMT -5. The time now is 04:42 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration