Search code examples
c++qtqmakeqtguiexiv2

Qt won't compile a project using exiv2.dll


I am desperately trying to get a focal length from a JPG picture using both Qt (for the GUI) and exiv2 (for the EXIF datas) on Windows, plus QtCreator as an IDE. I went through all the building of this so well documented library, which gave me some .dll for dynamic linking. The dlls are built in 32 bits, since I am using the 32 bits mingw in the QtCreator gui. There were no errors when building the libraries with visual studio, the dlls aren't empty, etc.

Here is the code of the constructor of the class using exiv2, where focalLength is a static attribute, img another attribute and path a QString:

img=new QImage(path);
std::string stdPath=path.toStdString();
if(!focalLength)
{
    Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(stdPath);
    image->readMetadata();
    Exiv2::ExifData &exifData = image->exifData();
    Exiv2::ExifKey key(Exif.Image.FocalLength);
    Exiv2::ExifData::const_iterator pos = exifData.findKey(key);
    if(pos!=exifData.end())
        focalLength=(double)pos->getValue();
    else
        focalLength(0);
}

the libraries (exiv2.dll and exiv2.lib) are in (projectPath)\exiv2_x32; the .pro file contains this, plus the headers and source files:

win32: LIBS += -L$$PWD/exiv2_x32/ -lexiv2
INCLUDEPATH += $$PWD/exiv2_x32
DEPENDPATH += $$PWD/exiv2_x32

But when I try to compile my code, I get the same output no matter how hard I try, "Exiv2 has not been declared", "expected ';' before 'image'", etc. although I executed qmake without errors. Why?

I'm a newbie at C++, so I might have missed an important thing or two or my understanding of dynamic linking could be wrong. But I really, really need help here. I can't believe it's so hard for me to get a focal length.

PS:When I try to link static libraries instead, the linker says it can't find a target for "exiv2.a".


Solution

  • If the headers are available in $$PWD/exiv2_x32, then you probably did some pity mistakes like including:

    #include "image.hpp"
    

    or messed up with your include guards, etc.