Desktop Qt 5.8.0 MinGW 32bit Windows app using ImageMagick libs

  • I have a working Desktop Qt 5.8.0 MinGW 32bit Windows project app, and want to try using ImageMagick to read various image formats. I downloaded the pre-built "ImageMagick-i686-pc-mingw32.tar.gz" binary release, since I do not want to use the MSVC compiled binary release.

    I am getting undefined references when building my Qt project. We have had no problems building with ImageMagick and running on Linux, only with Windows.

    Has anyone had any success using ImageMagick libraries with QT/MinGW on Windows? If so can you share your success?

  • Lifetime Qt Champion


    What exact error are you getting ?

    How does your .pro file look like ?

  • Here is the .pro file:

    QT += core

    TARGET = libcc_imagechunks
    TEMPLATE = lib


    SOURCES += cc_imagechunks.cpp

    HEADERS += cc_imagechunks.hpp

    win32 {
    INCLUDEPATH += "C:/Workspace/Qt/ImgAnnotation/ImageMagic-i686-pc-mingw32-6.8.5/include/ImageMagick-6"
    LIBS += -L"C:/Workspace/Qt/ImgAnnotation/ImageMagic-i686-pc-mingw32-6.8.5/bin" \
    -lMagick++-6.Q16-1 \
    -lMagickCore-6.Q16-1 \

    It generates lots of undefined references:

    debug/cc_imagechunks.o: In function ZN14CC_ImageChunks21initializeImageMagickEv': C:\Workspace\Qt\ImgAnnotation\build-cc_imagechunks-Desktop_Qt_5_8_0_MinGW_32bit-Debug/../CC_ImageChunks/SAVE/cc_imagechunks.cpp:85: undefined reference toMagick::CoderInfo::nameabi:cxx11 const'
    debug/cc_imagechunks.o: In function ZN14CC_ImageChunks12setImageTypeEv': C:\Workspace\Qt\ImgAnnotation\build-cc_imagechunks-Desktop_Qt_5_8_0_MinGW_32bit-Debug/../CC_ImageChunks/SAVE/cc_imagechunks.cpp:114: undefined reference toMagick::Image::ping(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
    C:\Workspace\Qt\ImgAnnotation\build-cc_imagechunks-Desktop_Qt_5_8_0_MinGW_32bit-Debug/../CC_ImageChunks/SAVE/cc_imagechunks.cpp:130: undefined reference to Magick::Image::magick[abi:cxx11]() const' debug/cc_imagechunks.o: In functionZN14CC_ImageChunks14IMReadToOCVMatEv':
    C:\Workspace\Qt\ImgAnnotation\build-cc_imagechunks-Desktop_Qt_5_8_0_MinGW_32bit-Debug/../CC_ImageChunks/SAVE/cc_imagechunks.cpp:144: undefined reference to Magick::Image::read(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' C:\Workspace\Qt\ImgAnnotation\build-cc_imagechunks-Desktop_Qt_5_8_0_MinGW_32bit-Debug/../CC_ImageChunks/SAVE/cc_imagechunks.cpp:160: undefined reference toMagick::Image::write(int, int, unsigned int, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, MagickCore::StorageType, void*)'
    debug/cc_imagechunks.o: In function ZN6Magick13coderInfoListINSt7__cxx114listINS_9CoderInfoESaIS3_EEEEEvPT_NS3_9MatchTypeES8_S8_': C:\Workspace\Qt\ImgAnnotation\build-cc_imagechunks-Desktop_Qt_5_8_0_MinGW_32bit-Debug/../ImageMagic-i686-pc-mingw32-6.8.5/include/ImageMagick-6/Magick++/STL.h:2080: undefined reference toMagick::CoderInfo::CoderInfo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
    collect2.exe: error: ld returned 1 exit status
    Makefile.Debug:63: recipe for target 'debug\libcc_imagechunks.dll' failed
    mingw32-make[1]: Leaving directory 'C:/Workspace/Qt/ImgAnnotation/build-cc_imagechunks-Desktop_Qt_5_8_0_MinGW_32bit-Debug'
    Makefile:34: recipe for target 'debug' failed
    mingw32-make[1]: *** [debug\libcc_imagechunks.dll] Error 1
    mingw32-make: *** [debug] Error 2
    07:16:33: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited with code 2.
    Error while building/deploying project cc_imagechunks (kit: Desktop Qt 5.8.0 MinGW 32bit)
    When executing step "Make"
    07:16:33: Elapsed time: 00:10.

  • Lifetime Qt Champion

    Are you sure you have an 32bit ImageMagick build ?

  • Yes, the download we are using is ImageMagick-i686-pc-mingw32.tar.gz, so we are presuming 32-bit. I do not know how to confirm it is a 32-bit build.

  • Lifetime Qt Champion

    You can use Dependency Walker for that.

    Did you modify the C++11 related flags in your .pro file ?

  • Thanks, I confirmed the ImageMagick dlls are 32 bit.

    I added "DEFINES += __MINGW32__" in the .pro file but that did not remove the undefined reference errors. Do you know if there are other defines I need to add?

  • I found the root cause of the issue.

    The following link explains about how changes were made to the C++ compiler necessary to conform to the 2011 C++ standard. The ImageMagick binary release built using the MinGW compiler was built prior to the the compiler changes and the Qt 5.8 MinGW compiler was built more recently.

    The following simple change to the .pro file fixed the problem:

    # Force pre C++11 style name mangling in order to be compatible with pre-built MinGW ImageMagick DLLs

  • Lifetime Qt Champion

    That's a sneaky one !

    Glad you found out and thanks for sharing !

Log in to reply