Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I use 64-bit MinGW with Qt?

How can I use 64-bit MinGW with Qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aaron Kim
    wrote on last edited by Aaron Kim
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • A Offline
        A Offline
        Aaron Kim
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ambershark
          wrote on last edited by
          #4

          @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.

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          A 1 Reply Last reply
          3
          • A ambershark

            @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.

            A Offline
            A Offline
            Aaron Kim
            wrote on last edited by Aaron Kim
            #5

            @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.

            A 1 Reply Last reply
            0
            • A Aaron Kim

              @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.

              A Offline
              A Offline
              ambershark
              wrote on last edited by
              #6

              @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

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved