简体   繁体   English

在 OpenCV dll 和 Qt 5.12 上找不到入口点

[英]Entry point not found on OpenCV dll with Qt 5.12

TLDR: Linking OpenCV with QT MingW makes application crash in Debug but not release. TLDR:将 OpenCV 与 QT 链接 MingW 会导致应用程序在调试时崩溃,但不会在发布时崩溃。

I am trying to use OpenCV in a large multi OS project based on Qt.我正在尝试在基于 Qt 的大型多操作系统项目中使用 OpenCV。 I have easily managed to build OpenCV for Mac and Linux but I am very much struggling to use it on Windows.我已经很容易地为 Mac 和 Linux 构建了 OpenCV,但我很难在 Windows 上使用它。

Environment:环境:

Qt 5.12.2 MinGW Qt 5.12.2 MinGW

MinGW 8.1.0 64bit MinGW 8.1.0 64位

OpenCV basically all versions since 4.1.0 OpenCV 基本上是 4.1.0 以后的所有版本

CMake 3.19 CMake 3.19

What I tried我试过的

  • I first tried to build OpenCV from source following his link https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows but had some issues running the application in Debug such as Entry Point not Found in opencv Library (exact error below) I first tried to build OpenCV from source following his link https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows but had some issues running the application in Debug such as Entry Point not Found in opencv Library (exact error below)

  • I lately used prebuilt packages from MSys2 using its pacman and tried version 4.2 to 4.5 without real success.我最近使用它的 pacman 使用了 MSys2 的预构建包,并尝试了 4.2 到 4.5 版本,但没有真正成功。 I managed a couple of time to link the OpenCV libraries from the installation path of msys (C:\msys64\mingw64\bin) and with this path in the environment PATH I was able to launch the application using the.exe generated by Qt.我设法从 msys 的安装路径 (C:\msys64\mingw64\bin) 链接 OpenCV 库,并在环境 PATH 中使用此路径,我能够使用 Qt 生成的.exe 启动应用程序。 However once I dragged the needed libraries into our third party libraries folder for deployment the application can't start anymore in Debug (with Qt nor with the.exe).但是,一旦我将所需的库拖到我们的第三方库文件夹中进行部署,应用程序就无法在 Debug 中启动(使用 Qt 或使用 .exe)。

  • I tried in Release mode and everything works fine我在发布模式下尝试过,一切正常

Now everytime I run the application in Debug with Qt the program crash immediately without even entering the main.现在,每次我使用 Qt 在调试中运行应用程序时,程序都会立即崩溃,甚至没有进入主程序。 I have the following error when I use the.exe:使用.exe时出现以下错误:

在此处输入图像描述

I have seen that it could be a TBB issue so I tried using a different version from MSys without success.我已经看到这可能是一个 TBB 问题,所以我尝试使用与 MSys 不同的版本,但没有成功。

I tried to change the PATH variables from Qt for the Build and the Run without success.我尝试将 PATH 变量从 Qt 更改为构建和运行,但没有成功。

My includes and Libs in my .pri are used as follow (they are all found during the build)我的.pri中的包含和 Lib 使用如下(它们都在构建过程中找到)

INCLUDEPATH += -I $$PWD/../../ext/OpenCV/include/opencv4
DEPENDPATH += -$$PWD/../../ext/OpenCV/include/opencv4

LIBS += -L$$PWD/../../ext/OpenCV/lib/$$OSFOLDER/$$ARCHFOLDER  -lopencv_imgproc430
LIBS += -L$$PWD/../../ext/OpenCV/lib/$$OSFOLDER/$$ARCHFOLDER  -lopencv_core430
LIBS += -L$$PWD/../../ext/OpenCV/lib/$$OSFOLDER/$$ARCHFOLDER  -lopencv_dnn430
LIBS += -L$$PWD/../../ext/OpenCV/lib/$$OSFOLDER/$$ARCHFOLDER  -lopencv_imgcodecs430
LIBS += -L$$PWD/../../ext/OpenCV/lib/$$OSFOLDER/$$ARCHFOLDER  -lopencv_highgui430

Okay so I finally managed to get it work: As I said in my question this error happens sometimes when the TBB version is not correct so here's what I did:好的,所以我终于设法让它工作:正如我在问题中所说,有时当 TBB 版本不正确时会发生此错误,所以这就是我所做的:

  • Build manually TBB with this repository: https://github.com/wjakob/tbb which contains a CMake-based build system of the official repository: https://github.com/oneapi-src/oneTBB使用此存储库手动构建 TBB: https://github.com/wjakob/tbb ,其中包含官方存储库的基于 CMake 的构建系统: https://github.com/oneapi-src/oneTBB

  • Build OpenCV with the version needed using the compilers you will use later in your application:使用您稍后将在应用程序中使用的编译器使用所需的版本构建 OpenCV:

    • Uncheck 'BUILD_TBB', check 'WITH_TBB' and point to the previously built TBB libraries and include.取消选中“BUILD_TBB”,选中“WITH_TBB”并指向先前构建的 TBB 库并包含。
    • Add the flags you need ( OPENCV_ENABLE_ALLOCATOR_STATS=OFF for instance ) and build it.添加您需要的标志(例如 OPENCV_ENABLE_ALLOCATOR_STATS=OFF )并构建它。
  • Finally add the libraries from 'path/to/opencv-build/bin' instead of 'path/to/opencv-build/install/bin' (maybe that's what we should always do but I wasn't sure) and it worked for me!最后从 'path/to/opencv-build/bin' 添加库而不是 'path/to/opencv-build/install/bin' (也许这是我们应该一直做的,但我不确定)并且它适用于我!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM