TIFF support with Static Qt (5.4.2) on Linux
-
I am working on an application that is able to save an image in various formats (JPEG, BMP, PNG or TIFF) using something like this:
QPixmap::fromImage().save()
This works correctly on Windows, OS X and Linux when dynamically linking with Qt. However on Linux, when I build Qt statically and the resulting application saves an image in TIFF format, then this results in a 0 byte file instead of a valid image. All other image formats are saved correctly.
On Windows the statically built Qt application works correctly and is able to save valid TIFF images.
For the record Qt was configured like this:
./configure -static -release -opensource -no-compile-examples -qt-xcb -fontconfigSo is there a known issue with TIFF support when Qt is statically linked on Linux and is it possible to work around this issue?
Thanks in advance,
Chris -
Hi and welcome to devnet,
What does
qDebug() << QImageWriter::supportedImageFormats()
return ? -
"When built, the Qt Image Formats plugins are located as dynamic libraries in the runtime plugin directory (typically plugins/imageformats), together with the default image format plugins."
Tiff support provided in plugin.
Since you build qt statically you can't have dynamically loaded plugins.
You may try to link it statically to your application.
Check http://doc.qt.io/qt-5/plugins-howto.htmlBut I am not sure if there is no legal issues with such approach.
-
Thanks for your help Alex. I understand that Tiff support is supplied in a plugin and this works well when dynamically linked.
From the documentation (which I have read and re-read many times!), I would expect to statically link with the TIFF plugin by adding this to my application's .pro file:
QTPLUGIN += qtiffHowever, this results in this warning when calling qmake:
Project WARNING: Plugin class name could not be determined for qtiff plugin.And this error when calling make:
/usr/bin/ld: cannot find -lqtiff
collect2: error: ld returned 1 exit statusThis seems to occur because the statically built Qt has not built the image plugins for static linking:
ls -l Qt/5.4/Src/qtbase/plugins/imageformats/
-rw-rw-r-- 1 u64 u64 40456 Jun 10 09:01 libqico.a
-rw-rw-r-- 1 u64 u64 882 Jun 10 09:01 libqico.prlAs for the legal issues, my application is open source (GPL v3) so I do not believe that there is a licensing issue with linking statically. As an aside the only reason I am statically linking is to reduce the number of dependencies when deploying a binary image on Linux machines.
-
Did you call configure in qtbase ?
-
Then check that the qtimageformats module has been built. tiff support comes from that one
-
Looking through the Qt directories I find this:
$ ls -l ~/Qt/5.4/qt-static/qtimageformats/plugins/imageformats
total 2996
-rw-rw-r-- 1 cgarry cgarry 66090 Jun 14 08:45 libqdds.a
-rw-rw-r-- 1 cgarry cgarry 931 Jun 14 08:44 libqdds.prl
-rw-rw-r-- 1 cgarry cgarry 54110 Jun 14 08:45 libqicns.a
-rw-rw-r-- 1 cgarry cgarry 934 Jun 14 08:45 libqicns.prl
-rw-rw-r-- 1 cgarry cgarry 925268 Jun 14 08:45 libqjp2.a
-rw-rw-r-- 1 cgarry cgarry 931 Jun 14 08:45 libqjp2.prl
-rw-rw-r-- 1 cgarry cgarry 597366 Jun 14 08:45 libqmng.a
-rw-rw-r-- 1 cgarry cgarry 934 Jun 14 08:45 libqmng.prl
-rw-rw-r-- 1 cgarry cgarry 40144 Jun 14 08:45 libqtga.a
-rw-rw-r-- 1 cgarry cgarry 931 Jun 14 08:45 libqtga.prl
-rw-rw-r-- 1 cgarry cgarry 684732 Jun 14 08:45 libqtiff.a
-rw-rw-r-- 1 cgarry cgarry 937 Jun 14 08:45 libqtiff.prl
-rw-rw-r-- 1 cgarry cgarry 27210 Jun 14 08:45 libqwbmp.a
-rw-rw-r-- 1 cgarry cgarry 934 Jun 14 08:45 libqwbmp.prl
-rw-rw-r-- 1 cgarry cgarry 622940 Jun 14 08:45 libqwebp.a
-rw-rw-r-- 1 cgarry cgarry 969 Jun 14 08:45 libqwebp.prlSo 'libqtiff.a' has at least been built. I shall try and dig into this further, but any tips on where to look next would be much appreciated.
Thanks,
Chris -
You probably already did
Q_IMPORT_PLUGIN(qtiff)
in your code ? -
If I add this to my main.ccp:
#include <QtPlugin>
Q_IMPORT_PLUGIN(qtiff)Then the build fails with:
../main.o: In function_GLOBAL__sub_I_main.cpp': main.cpp:(.text.startup+0x55): undefined reference to
qt_static_plugin_qtiff()'
collect2: ld returned 1 exit statusHowever, I have come to the conclusion that I am fighting the system here for no real good reason. Therefore, I have changed my approach to use dynamic linking instead of static linking (which I thought would be easier in the short term).
Using dynamic linking, my application now working without any problems and I do think this is the best way forward as I would like to produce source packages instead of binary packages.
Thanks,
Chris