Integrating exiv2 with Qt
-
Hi
I am trying to integrate exiv2 library with qt but when I tried to use a function, I get an error "undefined reference to".
I have written based on the code in this link example1.
MainWindow.cpp
void MainWindow::on_actionLoad_Image_triggered() { fileName = QFileDialog::getOpenFileName(this,tr("Open Image"), QDir::homePath(), tr("Image Files (*.png *.jpg *.bmp)")); QFile file(fileName); if(!file.exists()) return; std::string pth = fileName.toStdString(); Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(pth); }
.pro file
win32: LIBS += -L$$PWD/libs/exif/lib/ -llibexiv2.dll win32: LIBS += -L$$PWD/libs/exif/lib/ -llibz.dll win32: LIBS += -L$$PWD/libs/exif/lib/ -llibexpat.dll win32: LIBS += -L$$PWD/libs/exif/lib/ -lexiv2 win32: LIBS += -L$$PWD/libs/exif/lib/ -lz win32: LIBS += -L$$PWD/libs/exif/lib/ -lexpat INCLUDEPATH += $$PWD/libs/exif/include DEPENDPATH += $$PWD/libs/exif/include
Qt Version and Kit Details:
Qt 5.6.1 MinGW 32 bitError:
C:...\exifData\mainwindow.cpp:23: error: undefined reference to `Exiv2::ImageFactory::open(std::string const&, bool)'
-
Hi,
Your .pro file is wrong. You shouldn't link to .dll files but to .lib files.
So for exiv2 it should be something like
LIBS += -lexiv2
Did you also check that you are using the same compiler everywhere ? That's pretty important on Windows.
On a side note, there's no need to have several time the exact same folder you your
LIBS
line. -
Hi,
Your .pro file is wrong. You shouldn't link to .dll files but to .lib files.
So for exiv2 it should be something like
LIBS += -lexiv2
Did you also check that you are using the same compiler everywhere ? That's pretty important on Windows.
On a side note, there's no need to have several time the exact same folder you your
LIBS
line.@SGaist said in Integrating exiv2 with qt:
On a side note, there's no need to have several time the exact same folder you your LIBS line.
Thanks!! I will take note of that.
I have made a few changes and got to compile but it crashes on startup. On running with the debugger, I have got this error message. If possible please throw some light on this error message.
error:
During startup program exited with code 0x0000c135.pro file
win32{
LIBS += -L$$PWD/libs/exif/lib/ -llibexiv2.dllINCLUDEPATH += $$PWD/libs/exif/include
INCLUDEPATH += $$PWD/libs/exif/bin
DEPENDPATH += $$PWD/libs/exif/include
} -
Again, don't link against .dll.
Where is libexiv2.dll located on your computer ?
-
I have put it in a libs folder in the project directory.
When I import the libexiv2.dll.a via import external library in Qtcreator, It generates this in the .pro file. I have only added one line manually that is:
INCLUDEPATH += $$PWD/libs/exif/bin in the .pro file
Path of the dll:
$$PWD/libs/exif/lib/ -
Then you need to add that path to the PATH environment variable in the Run part of the Project panel. Otherwise your application won't find the .dll at startup. WARNING don't modify your system's PATH, just the one for running your application in Qt Creator.
-
Again: you have to add that path to the
PATH
environment variable. The loader doesn't care aboutEXIVPATH
to find the .dll it needs. -
Hi,
Your .pro file is wrong. You shouldn't link to .dll files but to .lib files.
So for exiv2 it should be something like
LIBS += -lexiv2
Did you also check that you are using the same compiler everywhere ? That's pretty important on Windows.
On a side note, there's no need to have several time the exact same folder you your
LIBS
line.@SGaist said in Integrating exiv2 with qt:
Did you also check that you are using the same compiler everywhere ? That's pretty important on Windows.
I have compiled it using msys and mingw. I am not able to get the mingw32 version
I am using Qt installed from qt-opensource-windows-x86-mingw492-5.6.1-1.exe file.
-
Do you mean that you get that error 139 at startup ?
-
AFAIK, it means that it fails to load a .dll Do you have other dependencies ?
-
local/bin
? On Windows ? -
Just to rule out the obvious, can you copy the exiv2 .dll in the same folder as the application and check whether the application starts ?
-
Just to rule out the obvious, can you copy the exiv2 .dll in the same folder as the application and check whether the application starts ?
Sorry for the late reply!!
Ya .. i have tried that already but gives the same error!
In the mean time I actually have tried many libraries and all are having same problem. So I guess there is a problem in either the build or the way of including the library. I will brief you exactly what I have done and the versions.
Build:
- I have successfully build the source code in the qt project folder using --prefix option with msys terminal with mingw compiler.
mingw32-g++.exe (GCC) 5.3.0
mingw32-gcc-5.3.0.exe (GCC) 5.3.0-
I am using Qt installed from qt-opensource-windows-x86-mingw492-5.6.1-1.exe
-
I have added mingw32-g++.exe (GCC) 5.3.0 as the compiler manually
-
I have added the external library (libexiv2.dll.a) in Qtcreator via Add Library external library and static mode.
-
I have also added to the PATH variable you have suggested.
The .pro reads this:
win32: LIBS += -L$$PWD/libs/exiv2build/lib/ -llibexiv2.dll INCLUDEPATH += $$PWD/libs/exiv2build/include DEPENDPATH += $$PWD/libs/exiv2build/include
It still gives me the error During startup program exited with code 0x0000c139.
Any suggestion on what might have gone wrong?
-
Do I understand understand correctly that you are trying to run application with libraries built with two different versions of MinGW ?
-
Do I understand understand correctly that you are trying to run application with libraries built with two different versions of MinGW ?