Results 1 to 4 of 4

Thread: Statically linked program doesn't load QImage from file.

  1. #1
    Join Date
    Aug 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Statically linked program doesn't load QImage from file.

    I have a small C++ program that works correctly when it is dynamically linked with Qt-4.4.3. However, when it is statically linked with Qt-4.4.3 it fails to load the image from a file into a QImage object.

    I am also using the open source Exiv2 library to access the image's header data.

    Given and image filename the program first opens and reads the metadata with the following line (where filename is a QString):

    Qt Code:
    1. _imageMetaData = Exiv2::ImageFactory::open(filename.toStdString());
    To copy to clipboard, switch view to plain text mode 

    Then sometime later is actually reads the image data with this line:

    Qt Code:
    1. // Load image from file into _currentImage.
    2. if (!_currentImage.load(filename)) {
    3. std::cout << "\nFailed to load image from file" << std::endl;
    4. }
    To copy to clipboard, switch view to plain text mode 


    I have linked the program to Qt-4.4.3 both dynamically with Qmake and with a simplified makefile and statically with Qmake and a simplified makefile. The results were the same (the statically linked versions do not load the image). I have installed both a dynamically linked version of Qt-4.4.3 (/usr/local/Trolltech/Qt-4.4.3) and a statically linked version (/usr/local/Trolltech/Qt-4.4.3-Static). Also, I set PATH to the statically linked version's bin directory before invoking qmake.

    Any thoughts or other experiments I can try? The .pro and makefile files follow.

    Thanks for your help,

    badjer1024

    This is the .pro file:

    Qt Code:
    1. TEMPLATE = app
    2. TARGET =
    3. DEPENDPATH += .
    4. INCLUDEPATH += .
    5. LIBS += -lexiv2
    6. # Input
    7. HEADERS += iMage_filearea.hpp \
    8. iMage_imagearea.hpp \
    9. iMage_imageheader.hpp \
    10. iMage_orientationdialog.hpp \
    11. iMage_picturearea.hpp \
    12. iMage_workarea.hpp
    13. SOURCES += iMage_filearea.cpp \
    14. iMage_imagearea.cpp \
    15. iMage_imageheader.cpp \
    16. iMage_main.cpp \
    17. iMage_orientationdialog.cpp \
    18. iMage_picturearea.cpp \
    19. iMage_workarea.cpp
    To copy to clipboard, switch view to plain text mode 

    and this is plagerized makefile:

    Qt Code:
    1. ####### Compiler, tools and options
    2.  
    3.  
    4. DEFINES = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB
    5.  
    6. CXX = g++
    7. CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
    8.  
    9. INCPATH = -I/usr/local/Trolltech/Qt-4.4.3-Static/include \
    10. -I/usr/local/Trolltech/Qt-4.4.3-Static/include/QtCore \
    11. -I/usr/local/Trolltech/Qt-4.4.3-Static/include/QtGui
    12.  
    13. LINK = g++
    14. LFLAGS = -pthread
    15.  
    16. LIBS = -L/usr/X11R6/lib -L/usr/local/Trolltech/Qt-4.4.3-Static/lib \
    17. -Wl,-Bstatic -lexiv2 -lQtGui -lQtCore \
    18. -Wl,-Bdynamic -lpng -lSM -lICE -lXi -lXrender \
    19. -lXrandr -lfreetype -lfontconfig -lXext -lX11 -lz -lm \
    20. -lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread
    21.  
    22. DEL_FILE = rm -f
    23.  
    24.  
    25. ####### Files
    26.  
    27. SOURCES = iMage_filearea.cpp \
    28. iMage_imagearea.cpp \
    29. iMage_imageheader.cpp \
    30. iMage_main.cpp \
    31. iMage_orientationdialog.cpp \
    32. iMage_picturearea.cpp \
    33. iMage_workarea.cpp \
    34. moc_iMage_filearea.cpp \
    35. moc_iMage_imagearea.cpp \
    36. moc_iMage_orientationdialog.cpp \
    37. moc_iMage_workarea.cpp
    38.  
    39. OBJECTS = iMage_filearea.o \
    40. iMage_imagearea.o \
    41. iMage_imageheader.o \
    42. iMage_main.o \
    43. iMage_orientationdialog.o \
    44. iMage_picturearea.o \
    45. iMage_workarea.o \
    46. moc_iMage_filearea.o \
    47. moc_iMage_imagearea.o \
    48. moc_iMage_orientationdialog.o \
    49. moc_iMage_workarea.o
    50.  
    51. TARGET = iMage
    52.  
    53.  
    54. ####### Build rules
    55.  
    56. all: Makefile $(TARGET)
    57.  
    58. clean:
    59. -$(DEL_FILE) $(OBJECTS)
    60. -$(DEL_FILE) *~ core *.core
    61.  
    62. ####### Link
    63.  
    64. $(TARGET): $(OBJECTS)
    65. $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(LIBS)
    66.  
    67.  
    68. ####### Compile
    69.  
    70. iMage_filearea.o: iMage_filearea.cpp iMage_filearea.hpp
    71. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_filearea.o iMage_filearea.cpp
    72.  
    73. iMage_imagearea.o: iMage_imagearea.cpp iMage_imagearea.hpp \
    74. iMage_workarea.hpp \
    75. iMage_imageheader.hpp \
    76. iMage_orientationdialog.hpp \
    77. iMage_picturearea.hpp
    78. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_imagearea.o iMage_imagearea.cpp
    79.  
    80. iMage_imageheader.o: iMage_imageheader.cpp iMage_imageheader.hpp \
    81. iMage_orientationdialog.hpp
    82. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_imageheader.o iMage_imageheader.cpp
    83.  
    84. iMage_main.o: iMage_main.cpp iMage_workarea.hpp
    85. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_main.o iMage_main.cpp
    86.  
    87. iMage_orientationdialog.o: iMage_orientationdialog.cpp iMage_orientationdialog.hpp
    88. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_orientationdialog.o iMage_orientationdialog.cpp
    89.  
    90. iMage_picturearea.o: iMage_picturearea.cpp iMage_picturearea.hpp
    91. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_picturearea.o iMage_picturearea.cpp
    92.  
    93. iMage_workarea.o: iMage_workarea.cpp iMage_workarea.hpp \
    94. iMage_filearea.hpp \
    95. iMage_imagearea.hpp \
    96. iMage_imageheader.hpp \
    97. iMage_orientationdialog.hpp \
    98. iMage_picturearea.hpp
    99. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_workarea.o iMage_workarea.cpp
    100.  
    101. moc_iMage_filearea.o: moc_iMage_filearea.cpp
    102. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_iMage_filearea.o moc_iMage_filearea.cpp
    103.  
    104. moc_iMage_imagearea.o: moc_iMage_imagearea.cpp
    105. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_iMage_imagearea.o moc_iMage_imagearea.cpp
    106.  
    107. moc_iMage_orientationdialog.o: moc_iMage_orientationdialog.cpp
    108. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_iMage_orientationdialog.o moc_iMage_orientationdialog.cpp
    109.  
    110. moc_iMage_workarea.o: moc_iMage_workarea.cpp
    111. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_iMage_workarea.o moc_iMage_workarea.cpp
    112.  
    113. ######## End of Makefile
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Leiden, The Netherlands
    Posts
    10
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Statically linked program doesn't load QImage from file.

    Did you compile-in the plugins of the various image formats as well in your static version?

    Might just not recognize the format if they are omitted as the static version cannot load plugins: http://doc.trolltech.com/4.4/plugins...static-plugins

  3. #3
    Join Date
    Aug 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Statically linked program doesn't load QImage from file.

    Thanks for the pointer to the plugins that QImage uses.

    I edited the .pro file as instructed.
    Qt Code:
    1. TEMPLATE = app
    2. TARGET = iMage
    3. DEPENDPATH += .
    4. INCLUDEPATH += .
    5. QTPLUGIN += qjpeg
    6. LIBS += -lexiv2 \
    7.  
    8. # Input
    9. HEADERS += iMage_filearea.hpp \
    10. iMage_imagearea.hpp \
    11. iMage_imageheader.hpp \
    12. iMage_orientationdialog.hpp \
    13. iMage_picturearea.hpp \
    14. iMage_workarea.hpp
    15. SOURCES += iMage_filearea.cpp \
    16. iMage_imagearea.cpp \
    17. iMage_imageheader.cpp \
    18. iMage_main.cpp \
    19. iMage_orientationdialog.cpp \
    20. iMage_picturearea.cpp \
    21. iMage_workarea.cpp
    To copy to clipboard, switch view to plain text mode 

    And the modified main.cpp is:

    Qt Code:
    1. #include <QApplication>
    2. #include <QtPlugin>
    3. #include <iostream>
    4.  
    5. Q_IMPORT_PLUGIN(qjpeg)
    6.  
    7. #include "iMage_workarea.hpp"
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11.  
    12. QApplication app(argc, argv);
    13.  
    14. WorkArea *workarea = new WorkArea (argv[1]);
    15.  
    16. return app.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 
    Then I ran:
    make clean
    /usr/local/Troltech/Qt4.4.3-Static/bin/qmake

    Everything compiled without error but the linker reported the following:

    Qt Code:
    1. g++ -Wl,-rpath,/usr/local/Trolltech/Qt-4.4.3-Static/lib -o iMage iMage_filearea.o iMage_imagearea.o iMage_imageheader.o iMage_main.o iMage_orientationdialog.o iMage_picturearea.o iMage_workarea.o moc_iMage_filearea.o moc_iMage_imagearea.o moc_iMage_orientationdialog.o moc_iMage_workarea.o -L/usr/local/Trolltech/Qt-4.4.3-Static/lib -lexiv2 -L/usr/local/Trolltech/Qt-4.4.3-Static/plugins/imageformats -lqjpeg -lQtGui -L/usr/local/Trolltech/Qt-4.4.3-Static/lib -L/usr/X11R6/lib -pthread -lpng -lSM -lICE -pthread -pthread -lXi -lXrender -lXrandr -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -pthread -lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread
    2. /usr/local/Trolltech/Qt-4.4.3-Static/plugins/imageformats/libqjpeg.a(qjpeghandler.o): In function `write_jpeg_image(QImage const&, QIODevice*, int)':
    3. qjpeghandler.cpp:(.text+0x414): undefined reference to `jpeg_std_error'
    4. qjpeghandler.cpp:(.text+0x45a): undefined reference to `jpeg_CreateCompress'
    5. qjpeghandler.cpp:(.text+0x4cc): undefined reference to `jpeg_set_defaults'
    6. qjpeghandler.cpp:(.text+0x8b4): undefined reference to `jpeg_set_quality'
    7. qjpeghandler.cpp:(.text+0x8ca): undefined reference to `jpeg_start_compress'
    8. qjpeghandler.cpp:(.text+0x956): undefined reference to `jpeg_write_scanlines'
    9. qjpeghandler.cpp:(.text+0x9e4): undefined reference to `jpeg_destroy_compress'
    10. qjpeghandler.cpp:(.text+0xd65): undefined reference to `jpeg_finish_compress'
    11. qjpeghandler.cpp:(.text+0xd73): undefined reference to `jpeg_destroy_compress'
    12. /usr/local/Trolltech/Qt-4.4.3-Static/plugins/imageformats/libqjpeg.a(qjpeghandler.o): In function `read_jpeg_image(QIODevice*, QImage*, QByteArray const&, QSize, int)':
    13. qjpeghandler.cpp:(.text+0x2bda): undefined reference to `jpeg_resync_to_restart'
    14. qjpeghandler.cpp:(.text+0x2c15): undefined reference to `jpeg_CreateDecompress'
    15. qjpeghandler.cpp:(.text+0x2c2f): undefined reference to `jpeg_std_error'
    16. qjpeghandler.cpp:(.text+0x2c6d): undefined reference to `jpeg_read_header'
    17. qjpeghandler.cpp:(.text+0x2d35): undefined reference to `jpeg_start_decompress'
    18. qjpeghandler.cpp:(.text+0x2eba): undefined reference to `jpeg_destroy_decompress'
    19. qjpeghandler.cpp:(.text+0x339f): undefined reference to `jpeg_read_scanlines'
    20. qjpeghandler.cpp:(.text+0x349e): undefined reference to `jpeg_finish_decompress'
    21. qjpeghandler.cpp:(.text+0x37a0): undefined reference to `jpeg_read_scanlines'
    22. qjpeghandler.cpp:(.text+0x37bc): undefined reference to `jpeg_finish_decompress'
    23. /usr/local/Trolltech/Qt-4.4.3-Static/plugins/imageformats/libqjpeg.a(qjpeghandler.o): In function `jpegSmoothScaler::scanLine(int, QImage const*)':
    24. qjpeghandler.cpp:(.text._ZN16jpegSmoothScaler8scanLineEiPK6QImage[jpegSmoothScaler::scanLine(int, QImage const*)]+0x3b): undefined reference to `jpeg_read_scanlines'
    25. collect2: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 

    This is so tantalizingly close!
    I am missing an additional library?

    Thanks again for your help,

    Badjer1024

  4. #4
    Join Date
    Aug 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs up Re: Statically linked program doesn't load QImage from file.

    After thinking about it I decided to run ldd against the qjpeg plugin to see what it depended on in the hope that an obvious library would be there. There was an obvious library that it needed which was libjpeg.nn.so in /usr/lib. (Note: ldd complains about static libs so I ran it against the dynamic version of qjpeg.) I checked in /usr/lib and there was also a .a version. After adding the appropriate -L and -l flags to the static portion of LFLAGS in the makefile it linked w/o errors and the statically linked program display the image!

    Thanks again for your help!!!

Similar Threads

  1. Application seems not to be linked statically
    By Boron in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd April 2008, 17:14
  2. Program not compiling on Fresh install of Leopard
    By dvmorris in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2007, 10:22
  3. Replies: 5
    Last Post: 29th October 2007, 22:49
  4. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04:19
  5. Replies: 2
    Last Post: 13th September 2006, 09:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.