Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How can I use 64-bit MinGW with Qt?



  • Hello, I'm struggling with using OpenCV with Qt. I got the following error.

    D:\opencv-build\bin\libopencv_core400.dll:-1: error: file not recognized: File format not recognized
    

    And I'm suspecting that this is related to 32bit-64bit problem. These are the reasons.

    • I built the OpenCV with MinGW 8.1.0 64bit.
    • If I try compiling a simple cpp file which consists of a single code with cv::Mat, it works fine without any error.

    So, I tried using my MinGW 8.1.0 64 bit instead of default Qt MinGW (5.3.0 32bit) to compile the project.
    0_1541956855309_a.PNG
    1_1541956855311_b.PNG

    And then, it complains that it can not find libs. But I checked that certainly the files are there.
    So I changed all the lines like below.

    LIBS += "D:/opencv-build/bin/libopencv_core400.dll"
    LIBS += "D:/opencv-build/bin/libopencv_highgui400.dll"
    LIBS += "D:/opencv-build/bin/libopencv_imgcodecs400.dll"
    ...
    

    In the end, it fails with the message

    collect2.exe: error: ld returned 5 exit status
    

    Which seems like a link error.
    How can I solve this problem?


  • Lifetime Qt Champion

    Hi,

    You should build OpenCV with the same compiler as Qt, or at least make a 32bit build.



  • Then do you mean that it is not possible to use 64-bit MinGW with Qt?


  • Moderators

    @Aaron-Kim said in How can I use 64-bit MinGW with Qt?:

    It's possible to use Mingw64 with Qt. What @SGaist was saying is you are trying to use an OpenCV binary from MSVC. That won't work.

    D:\opencv-build\bin\libopencv_core400.dll:-1: error: file not recognized: File format not recognized

    The error message basically tells you this. But if you needed another hint the .dll extension gives it away. Mingw uses posix style library names like .a and .so.

    So you will have to build opencv with mingw64 and then use that in your build of Qt with mingw64. That will get you past that problem.

    However be warned building Qt with mingw in general can be a pain and really hard with 64 bit mingw. Make sure you use the correct versions of mingw (the same ones Qt build their libraries with for distribution) or you will run into a lot of trouble.



  • @ambershark

    you are trying to use an OpenCV binary from MSVC. That won't work.

    What does this exactly mean? I built OpenCV with mingw 64bit, not MSVC.


  • Moderators

    @Aaron-Kim So it seems that mingw64 can output libraries with the extension dll. So I lied about that part above.

    So if you're sure you are using libraries compiled with the same compiler and architecture then it's something else causing them not to be found.

    I see you are using -llibopencv_core400 for a file libopencv_core400.dll. The proper line for that is -lopencv_core400, you drop the lib prefix and the extension suffix.

    The second part where you forced a full filename will work too (however it's not a good practice. Hard coded paths are a big reason for that. So along those lines what is the output from either fixing your -l lines or using the second set. You just show the exit error code from the linker. You definitely have a linking problem but without the actual errors it's hard to help you figure out what they are.

    Things that cause libraries that "should" be found to not be found:

    1. Different compilers
    2. Different architectures
    3. Path not set properly with -L
    4. Library name not correct with -l

Log in to reply