April 8, 2011

soroush soroush
Ant Farmer
814 posts

Statlic linking of Qt and C++ libraries

 

Hi

I’m writing a program using Qt and libstd++. target machine probably does not have any of them installed. I would like to statically link all Qt and other c++ libraries used in my application. Adding CONFIG += static into the .pro file didn’t help.

10 replies

April 8, 2011

ZapB ZapB
Hobby Entomologist
1422 posts

You have to build Qt itself as a static library. Check out the help for the configure script of Qt fo rmore info but you will at least need to use the -static option when configuring Qt.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

April 8, 2011

soroush soroush
Ant Farmer
814 posts

I have installed Qt from Ubuntu repository. Could you tell me please how do I statically re-compile Qt? I have to install Qt development files?

April 8, 2011

ZapB ZapB
Hobby Entomologist
1422 posts

Yes download the qt-everywhere source tarball from here [qt.nokia.com]. Then extract it somewhere, configure it with something like:

  1. ./configure -static -prefix $HOME/development/qt-static-4.7.2

Then make and make install as per usual.

Once that is done, simply use the version of qmake that gets installed rather than the system-supplied qmake. You can do this by editing your $PATH environment variable to pick up your new qmake first or you could set up and alias or just use the full path to it.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

April 8, 2011

soroush soroush
Ant Farmer
814 posts

Ok, I’m going to download and compile.

Thank you.

April 9, 2011

soroush soroush
Ant Farmer
814 posts

Ok, I’m unable to compile Qt ! my download failed last day (when I moved my notebook from university to home :-( and I have to redownload it.

Currently I have installed qt-sdk 64-bit version from repositories. Is there a way to link shared libraries like as static libraries? I also have to compile a 32-bit program :-) I’m looking for a way to avoid download and compile…

April 9, 2011

ZapB ZapB
Hobby Entomologist
1422 posts

I thought that the sdk shipped the sources along with it? Just build those if you already have them to hand. You can rebuild and install in as many configurations as you like. The same source tree applies to all.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

April 9, 2011

soroush soroush
Ant Farmer
814 posts

There are header files in /usr/include/qt4 directory. But there are no any configuration or make or even source codes. I don’t know if they are correct sources or not, or if I will be able to revert them to previous state or not. think there are just headers and compiled libraries included in packages.

I’m going to download the source code.

Thanks you :-)

April 9, 2011

Gerolf Gerolf
Robot Herder
3235 posts

If you download the SDK beta (and I think also RC) the structure is changed :-)
You have the headers without links, no sources inside. You can also download / install the sourc4s with the installer, but it is different from the pure source package where the include files from include point to the sources dir.

To rebuild Qt, you now have to download the real source zip or tar file.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

April 24, 2011

soroush soroush
Ant Farmer
814 posts

./configure -static -prefix $HOME/development/qt-static-4.7.2

I tested my program in target machine. It works!

Thanks in advance :-)

April 24, 2011

ZapB ZapB
Hobby Entomologist
1422 posts

Congratulations! Good luck with the rest of your project.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

 
  ‹‹ [Split] Font color in QTextEdit      Preprocessor macro and Q_INVOKABLE ››

You must log in to post a reply. Not a member yet? Register here!