badjer1024
16th March 2009, 16:52
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 (http://www.exiv2.org/) 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):
_imageMetaData = Exiv2::ImageFactory::open(filename.toStdString());
Then sometime later is actually reads the image data with this line:
// Load image from file into _currentImage.
if (!_currentImage.load(filename)) {
std::cout << "\nFailed to load image from file" << std::endl;
}
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:
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
LIBS += -lexiv2
# Input
HEADERS += iMage_filearea.hpp \
iMage_imagearea.hpp \
iMage_imageheader.hpp \
iMage_orientationdialog.hpp \
iMage_picturearea.hpp \
iMage_workarea.hpp
SOURCES += iMage_filearea.cpp \
iMage_imagearea.cpp \
iMage_imageheader.cpp \
iMage_main.cpp \
iMage_orientationdialog.cpp \
iMage_picturearea.cpp \
iMage_workarea.cpp
and this is plagerized makefile:
####### Compiler, tools and options
DEFINES = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB
CXX = g++
CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
INCPATH = -I/usr/local/Trolltech/Qt-4.4.3-Static/include \
-I/usr/local/Trolltech/Qt-4.4.3-Static/include/QtCore \
-I/usr/local/Trolltech/Qt-4.4.3-Static/include/QtGui
LINK = g++
LFLAGS = -pthread
LIBS = -L/usr/X11R6/lib -L/usr/local/Trolltech/Qt-4.4.3-Static/lib \
-Wl,-Bstatic -lexiv2 -lQtGui -lQtCore \
-Wl,-Bdynamic -lpng -lSM -lICE -lXi -lXrender \
-lXrandr -lfreetype -lfontconfig -lXext -lX11 -lz -lm \
-lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread
DEL_FILE = rm -f
####### Files
SOURCES = iMage_filearea.cpp \
iMage_imagearea.cpp \
iMage_imageheader.cpp \
iMage_main.cpp \
iMage_orientationdialog.cpp \
iMage_picturearea.cpp \
iMage_workarea.cpp \
moc_iMage_filearea.cpp \
moc_iMage_imagearea.cpp \
moc_iMage_orientationdialog.cpp \
moc_iMage_workarea.cpp
OBJECTS = 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
TARGET = iMage
####### Build rules
all: Makefile $(TARGET)
clean:
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core
####### Link
$(TARGET): $(OBJECTS)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(LIBS)
####### Compile
iMage_filearea.o: iMage_filearea.cpp iMage_filearea.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_filearea.o iMage_filearea.cpp
iMage_imagearea.o: iMage_imagearea.cpp iMage_imagearea.hpp \
iMage_workarea.hpp \
iMage_imageheader.hpp \
iMage_orientationdialog.hpp \
iMage_picturearea.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_imagearea.o iMage_imagearea.cpp
iMage_imageheader.o: iMage_imageheader.cpp iMage_imageheader.hpp \
iMage_orientationdialog.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_imageheader.o iMage_imageheader.cpp
iMage_main.o: iMage_main.cpp iMage_workarea.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_main.o iMage_main.cpp
iMage_orientationdialog.o: iMage_orientationdialog.cpp iMage_orientationdialog.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_orientationdialog.o iMage_orientationdialog.cpp
iMage_picturearea.o: iMage_picturearea.cpp iMage_picturearea.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_picturearea.o iMage_picturearea.cpp
iMage_workarea.o: iMage_workarea.cpp iMage_workarea.hpp \
iMage_filearea.hpp \
iMage_imagearea.hpp \
iMage_imageheader.hpp \
iMage_orientationdialog.hpp \
iMage_picturearea.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_workarea.o iMage_workarea.cpp
moc_iMage_filearea.o: moc_iMage_filearea.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_iMage_filearea.o moc_iMage_filearea.cpp
moc_iMage_imagearea.o: moc_iMage_imagearea.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_iMage_imagearea.o moc_iMage_imagearea.cpp
moc_iMage_orientationdialog.o: moc_iMage_orientationdialog.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_iMage_orientationdialog.o moc_iMage_orientationdialog.cpp
moc_iMage_workarea.o: moc_iMage_workarea.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_iMage_workarea.o moc_iMage_workarea.cpp
######## End of Makefile
I am also using the open source Exiv2 (http://www.exiv2.org/) 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):
_imageMetaData = Exiv2::ImageFactory::open(filename.toStdString());
Then sometime later is actually reads the image data with this line:
// Load image from file into _currentImage.
if (!_currentImage.load(filename)) {
std::cout << "\nFailed to load image from file" << std::endl;
}
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:
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
LIBS += -lexiv2
# Input
HEADERS += iMage_filearea.hpp \
iMage_imagearea.hpp \
iMage_imageheader.hpp \
iMage_orientationdialog.hpp \
iMage_picturearea.hpp \
iMage_workarea.hpp
SOURCES += iMage_filearea.cpp \
iMage_imagearea.cpp \
iMage_imageheader.cpp \
iMage_main.cpp \
iMage_orientationdialog.cpp \
iMage_picturearea.cpp \
iMage_workarea.cpp
and this is plagerized makefile:
####### Compiler, tools and options
DEFINES = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB
CXX = g++
CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
INCPATH = -I/usr/local/Trolltech/Qt-4.4.3-Static/include \
-I/usr/local/Trolltech/Qt-4.4.3-Static/include/QtCore \
-I/usr/local/Trolltech/Qt-4.4.3-Static/include/QtGui
LINK = g++
LFLAGS = -pthread
LIBS = -L/usr/X11R6/lib -L/usr/local/Trolltech/Qt-4.4.3-Static/lib \
-Wl,-Bstatic -lexiv2 -lQtGui -lQtCore \
-Wl,-Bdynamic -lpng -lSM -lICE -lXi -lXrender \
-lXrandr -lfreetype -lfontconfig -lXext -lX11 -lz -lm \
-lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread
DEL_FILE = rm -f
####### Files
SOURCES = iMage_filearea.cpp \
iMage_imagearea.cpp \
iMage_imageheader.cpp \
iMage_main.cpp \
iMage_orientationdialog.cpp \
iMage_picturearea.cpp \
iMage_workarea.cpp \
moc_iMage_filearea.cpp \
moc_iMage_imagearea.cpp \
moc_iMage_orientationdialog.cpp \
moc_iMage_workarea.cpp
OBJECTS = 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
TARGET = iMage
####### Build rules
all: Makefile $(TARGET)
clean:
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core
####### Link
$(TARGET): $(OBJECTS)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(LIBS)
####### Compile
iMage_filearea.o: iMage_filearea.cpp iMage_filearea.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_filearea.o iMage_filearea.cpp
iMage_imagearea.o: iMage_imagearea.cpp iMage_imagearea.hpp \
iMage_workarea.hpp \
iMage_imageheader.hpp \
iMage_orientationdialog.hpp \
iMage_picturearea.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_imagearea.o iMage_imagearea.cpp
iMage_imageheader.o: iMage_imageheader.cpp iMage_imageheader.hpp \
iMage_orientationdialog.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_imageheader.o iMage_imageheader.cpp
iMage_main.o: iMage_main.cpp iMage_workarea.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_main.o iMage_main.cpp
iMage_orientationdialog.o: iMage_orientationdialog.cpp iMage_orientationdialog.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_orientationdialog.o iMage_orientationdialog.cpp
iMage_picturearea.o: iMage_picturearea.cpp iMage_picturearea.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_picturearea.o iMage_picturearea.cpp
iMage_workarea.o: iMage_workarea.cpp iMage_workarea.hpp \
iMage_filearea.hpp \
iMage_imagearea.hpp \
iMage_imageheader.hpp \
iMage_orientationdialog.hpp \
iMage_picturearea.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o iMage_workarea.o iMage_workarea.cpp
moc_iMage_filearea.o: moc_iMage_filearea.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_iMage_filearea.o moc_iMage_filearea.cpp
moc_iMage_imagearea.o: moc_iMage_imagearea.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_iMage_imagearea.o moc_iMage_imagearea.cpp
moc_iMage_orientationdialog.o: moc_iMage_orientationdialog.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_iMage_orientationdialog.o moc_iMage_orientationdialog.cpp
moc_iMage_workarea.o: moc_iMage_workarea.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_iMage_workarea.o moc_iMage_workarea.cpp
######## End of Makefile