PDA

View Full Version : Qt application is not compiling with static linking?



gurmeetsingh
26th January 2012, 14:36
Hi,

1. I am developing a GUI based Qt Desktop application. I want to compile this application with static linking so that it will run on any ubuntu system.
I am http://www.qtcentre.org/wiki/index.php?title=Building_static_applications#Build ing_a_static_application link to compile the source with static linking but it is not working for me.

export PATH="$PATH:/usr/local/Trolltech/Qt-4.7.4/bin" is setting the environment variable but when logout or close the terminal and #echo $PATH, then qmake's path is not in this.

2. can i install only source package on ubuntu for developement without any other Qt installation and how?

3. Is there any way to do setting for static linking in Qt creator.

Please help
Thanks

MarekR22
26th January 2012, 15:31
I want to compile this application with static linking so that it will run on any ubuntu system.
So why you need static linking? Qt is a part of Ubuntu distribution!
To deploy app you should use debian packege system with marked required dependency. Then when package is installed calling:

sudo apt-get install -f
will install all needed libraries (of Qt).
In case when package is install from package repository everything should be automatic.

If you don't know how to make debian package just install qt-libraries manually:

sudo apt-get install libqt4-dev
will install most of the Qt libraries.

You can try install minimal number of packages (depending what kind of features you app is using):

sudo apt-get install libqt4-gui libqt4-core

gurmeetsingh
27th January 2012, 03:56
Thanks Marek for your response.

I am developing a GUI based application which will install printer driver on ubuntu. It is actually a setup kind of executable as it is required by the client.
While installing the printer, it will give flexibility to user to choose port, set name of printer etc.
How i can acheive this?

Can you provide any step by step guide to create .deb package as it is also required by client and i have not found any useful link reason being newbie?

Thanks.

ChrisW67
27th January 2012, 06:32
1. I am developing a GUI based Qt Desktop application. I want to compile this application with static linking so that it will run on any ubuntu system. I am http://www.qtcentre.org/wiki/index.php?title=Building_static_applications#Build ing_a_static_application link to compile the source with static linking but it is not working for me.

export PATH="$PATH:/usr/local/Trolltech/Qt-4.7.4/bin" is setting the environment variable but when logout or close the terminal and #echo $PATH, then qmake's path is not in this. Environment variables set (and exported) in a shell are available for the life of that shell to any sub-process. This is NOT setting the default system or user path in a persistent way (read https://help.ubuntu.com/community/EnvironmentVariables, a mere Google search away) .

I assume that /usr/local/Trolltech/Qt-4.7.4 is where you have installed a version of Qt built for static linkage, otherwise these second part of this doesn't seem related to the first. Rather than try to set a system-wide path that includes this copy of Qt (as the default) perhaps you should just tell your copy of Qt Creator about this install of Qt and let it worry about the path. That's done from The Tool menu, Options, Qt4 panel.


2. can i install only source package on ubuntu for developement without any other Qt installation and how?
No. To compile from source you need a compiled Qt installation as well as the matching compiler and any other referenced libraries.


3. Is there any way to do setting for static linking in Qt creator.
Build a static linkage version of Qt. Tell Qt Creator where to find it (see above). Build your project using that copy of Qt. Profit!


Can you provide any step by step guide to create .deb package as it is also required by client and i have not found any useful link reason being newbie?
Ubuntu Packaging Guide (https://wiki.ubuntu.com/PackagingGuide/Complete). Deployment packaging is not trivial, and every application is different. You will be lucky to find a cut-and-paste solution. From your struggle with the PATH I suspect your level of UNIX system understanding will make building a customer-proof package quite a challenge for you.

gurmeetsingh
27th January 2012, 08:50
Thanks Chris for your valueable reply.

I am MS VC++ developer on MS WIndows and newbie on ubuntu as well as Qt.


I assume that /usr/local/Trolltech/Qt-4.7.4 is where you have installed a version of Qt built for static linkage, otherwise these second part of this doesn't seem related to the first. Rather than try to set a system-wide path that includes this copy of Qt (as the default) perhaps you should just tell your copy of Qt Creator about this install of Qt and let it worry about the path. That's done from The Tool menu, Options, Qt4 panel.

I am unable to set the PATH for my application in Tools, options, Qt4 panel. I can change other parameters like 4.7.4 and Desktop Qt 4.7.3 for gcc etc but Qt in Path is disabled.
Attached herewith the screen shot for the same.

one more question please
I have installed Qt 4.7.4, can i build my application with Qt 4.8.0 source for static linkage?

Thanks in advance.

wysota
27th January 2012, 14:04
I am unable to set the PATH for my application in Tools, options, Qt4 panel.
Please read Chris's post again. He didn't tell you to set PATH for your program in there.


I can change other parameters like 4.7.4 and Desktop Qt 4.7.3 for gcc etc but Qt in Path is disabled.
Click on the big "Add" button on the right of the window.

Before continuing please first think what is the goal you want to achieve by doing the action you are going to do. Right now you are acting like putting a monkey in front of a typewriter hoping it will write an epic story by randomly striking keys.

ChrisW67
28th January 2012, 00:15
"Qt in PATH" is not editable because there is either is, or is not, a qmake in the system PATH and you cannot change that situation from Qt Creator. It is largely irrelevant here because you don't want to use the Qt in the system PATH anyway.

You can define any number of Qt versions/builds by using, as wysota elegantly pointed out, the Add button and then tell Creator where to find the qmake from that copy of Qt. Once you have a copy of Qt identified to the IDE you can associate that version with your Projects Build Settings (see the left tool bar in Creator). Qt Creator will then use that qmake to build your application, and that qmake will ensure that you use its associated files when building. Since you will be using a statically linked Qt, the resulting executable should have few, if any, external dependencies at run time.

gurmeetsingh
31st January 2012, 08:21
Hi Chris,

I have compiled Qt application with static linking.
The size of previous applicatio with dynamic linking was 8.7 KB and after compiling with static linking it becomes 13.2 MB. It is just a demo application which displays a label only.
After compiling with static linking, it is again not running on another ubuntu system.
can you suggest what may be the problem?

wysota
31st January 2012, 10:27
Please run ldd yourapplicationexe and post the result. Do the same on the other system and also post the result.

gurmeetsingh
31st January 2012, 11:17
ldd <appName>

Output on my system


linux-gate.so.1 => (0x0080c000)
libjpeg.so.62 => /usr/lib/i386-linux-gnu/libjpeg.so.62 (0x002e3000)
libmng.so.1 => /usr/lib/i386-linux-gnu/libmng.so.1 (0x00e5f000)
libtiff.so.4 => /usr/lib/i386-linux-gnu/libtiff.so.4 (0x00110000)
libpng12.so.0 => /lib/i386-linux-gnu/libpng12.so.0 (0x00aec000)
libgobject-2.0.so.0 => /usr/lib/i386-linux-gnu/libgobject-2.0.so.0 (0x00bda000)
libSM.so.6 => /usr/lib/i386-linux-gnu/libSM.so.6 (0x00b1f000)
libICE.so.6 => /usr/lib/i386-linux-gnu/libICE.so.6 (0x00335000)
libXrender.so.1 => /usr/lib/i386-linux-gnu/libXrender.so.1 (0x00173000)
libfontconfig.so.1 => /usr/lib/i386-linux-gnu/libfontconfig.so.1 (0x009b5000)
libfreetype.so.6 => /usr/lib/i386-linux-gnu/libfreetype.so.6 (0x0017e000)
libXext.so.6 => /usr/lib/i386-linux-gnu/libXext.so.6 (0x009eb000)
libX11.so.6 => /usr/lib/i386-linux-gnu/libX11.so.6 (0x0034f000)
libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0x00627000)
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0x0030a000)
libgthread-2.0.so.0 => /usr/lib/i386-linux-gnu/libgthread-2.0.so.0 (0x00262000)
librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0x00f1e000)
libglib-2.0.so.0 => /lib/i386-linux-gnu/libglib-2.0.so.0 (0x00485000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0x00d2d000)
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0x00d5e000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0x0088a000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0x002bc000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x0063c000)
/lib/ld-linux.so.2 (0x00f9c000)
liblcms.so.1 => /usr/lib/i386-linux-gnu/liblcms.so.1 (0x00215000)
libffi.so.6 => /usr/lib/i386-linux-gnu/libffi.so.6 (0x0024e000)
libuuid.so.1 => /lib/i386-linux-gnu/libuuid.so.1 (0x00255000)
libexpat.so.1 => /lib/i386-linux-gnu/libexpat.so.1 (0x008f6000)
libxcb.so.1 => /usr/lib/i386-linux-gnu/libxcb.so.1 (0x00268000)
libpcre.so.3 => /lib/i386-linux-gnu/libpcre.so.3 (0x00a52000)
libXau.so.6 => /usr/lib/i386-linux-gnu/libXau.so.6 (0x0025b000)
libXdmcp.so.6 => /usr/lib/i386-linux-gnu/libXdmcp.so.6 (0x00c3f000)


Output on another system


not a dynamic execuatble


Thanks.

wysota
31st January 2012, 13:12
So first of all all these from the first printout are dynamic libraries your app depends on. If you want your program to be trully static, you need static versions of most of these so that you can link static Qt against them.

Second of all it seems the architecture on the second machine is different than the one on the first.

What does file <yourapp> show and what does uname -a return on both machines?

gurmeetsingh
31st January 2012, 13:14
Hi Wysota,

Output on my system:


file <myApp>:
Demo_: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
uname -a
Linux ravi-desktop 3.0.0-15-generic #26-Ubuntu SMP Fri Jan 20 15:59:53 UTC 2012 i686 i686 i386 GNU/Linux


Output on Another System:


file <myApp>:
Demo_: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
uname -a:
Linux ubuntu 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux


Is the problem due to architecture difference?

Thanks.

wysota
31st January 2012, 13:28
Aparently the other system doesn't have support for running 32bit binaries.

gurmeetsingh
31st January 2012, 14:01
Thanks Wysota and Chriss for your valuable reply.

I will test it on system having same configuration as my system.

If i face problem then i will again irritate you.

Thanks:D

mathewjmanavalan
24th April 2012, 06:21
Hi ChrisW67,

I wanted to build a Qt application with static link and stumbled upon this post. When i try to include a new PATH to the new (static) qmake, it says Qt version not installed properly" -> How do i rectify this ?