无法使用opencv运行简单程序,出现错误“找不到过程入口点”。

3
以下代码编译无误,但在我尝试执行时,出现了“动态链接库libopencv_core2413.dll中找不到过程入口_ZSt24__throw_out_of_range_fmtPKcz”的错误提示。原始信息为葡萄牙语。
#include "opencv2/highgui.hpp"
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/opencv_modules.hpp"

int main()
{
  cv::Mat a;
  return 0;
}

首先,我从sourceforge链接下载了源代码,然后构建它。Cmake版本为3.5.0-rc2,mingw版本为4.9.3,opencv版本为2.4.13。我在mingw上安装了haskell和allegro5库。

下载完成后,我将其解压到了C:/opencv目录下。使用cmake-gui,我将源文件夹设置为C:/opencv/sources,构建文件夹设置为C:/opencv/build。关于配置标志,我只取消了BUILD_opencv_pyhon的标记,因为我没有安装python。这是配置和生成步骤的日志:

Detected version of GNU GCC: 49 (409)
CUDA compilation is disabled (due to only Visual Studio compiler supported on your platform).

General configuration for OpenCV 2.4.13 =====================================
  Version control:               unknown

  Platform:
    Host:                        Windows 10.0.10586 AMD64
    CMake:                       3.5.0-rc2
    CMake generator:             MinGW Makefiles
    CMake build tool:            C:/MinGW/bin/mingw32-make.exe
    Configuration:               Release

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                C:/MinGW/bin/g++.exe  (ver 4.9.3)
    C++ flags (Release):         -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-array-bounds -Wno-aggressive-loop-optimizations -fdiagnostics-show-option -march=i686 -fomit-frame-pointer -msse -msse2 -mfpmath=sse -ffunction-sections -O2 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-array-bounds -Wno-aggressive-loop-optimizations -fdiagnostics-show-option -march=i686 -fomit-frame-pointer -msse -msse2 -mfpmath=sse -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  C:/MinGW/bin/gcc.exe
    C flags (Release):           -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-array-bounds -Wno-aggressive-loop-optimizations -fdiagnostics-show-option -march=i686 -fomit-frame-pointer -msse -msse2 -mfpmath=sse -ffunction-sections -O2 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-array-bounds -Wno-aggressive-loop-optimizations -fdiagnostics-show-option -march=i686 -fomit-frame-pointer -msse -msse2 -mfpmath=sse -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      
    Linker flags (Debug):        
    Precompiled headers:         YES

  OpenCV modules:
    To be built:                 core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu ocl nonfree contrib stitching superres ts videostab
    Disabled:                    python world
    Disabled by dependency:      -
    Unavailable:                 androidcamera dynamicuda java viz

  Windows RT support:            NO

  GUI: 
    QT:                          NO
    Win32 UI:                    YES
    OpenGL support:              NO
    VTK support:                 NO

  Media I/O: 
    ZLib:                        build (ver 1.2.7)
    JPEG:                        build (ver 62)
    PNG:                         build (ver 1.5.12)
    TIFF:                        build (ver 42 - 4.0.2)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)

  Video I/O:
    Video for Windows:           YES
    DC1394 1.x:                  NO
    DC1394 2.x:                  NO
    FFMPEG:                      YES (prebuilt binaries)
      codec:                     YES (ver 55.18.102)
      format:                    YES (ver 55.12.100)
      util:                      YES (ver 52.38.100)
      swscale:                   YES (ver 2.3.100)
      resample:                  NO
      gentoo-style:              YES
    OpenNI:                      NO
    OpenNI PrimeSensor Modules:  NO
    PvAPI:                       NO
    GigEVisionSDK:               NO
    DirectShow:                  YES
    Media Foundation:            NO
    XIMEA:                       NO
    Intel PerC:                  NO

  Other third-party libraries:
    Use IPP:                     NO
    Use Eigen:                   NO
    Use TBB:                     NO
    Use OpenMP:                  NO
    Use GCD                      NO
    Use Concurrency              NO
    Use C=:                      NO
    Use Cuda:                    NO
    Use OpenCL:                  YES

  OpenCL:
    Version:                     dynamic
    Include path:                C:/opencv/sources/3rdparty/include/opencl/1.2
    Use AMD FFT:                 NO
    Use AMD BLAS:                NO

  Python:
    Interpreter:                 D:/Ferramentas/[Ferramenta]_Phyton/python.exe (ver 2.7.10)

  Java:
    ant:                         NO
    JNI:                         C:/Program Files/Java/jdk1.8.0_91/include C:/Program Files/Java/jdk1.8.0_91/include/win32 C:/Program Files/Java/jdk1.8.0_91/include
    Java tests:                  NO

  Tests and samples:
    Tests:                       YES
    Performance tests:           YES
    C/C++ Examples:              NO

  Install path:                  C:/opencv/build/install

  cvconfig.h is in:              C:/opencv/build
-----------------------------------------------------------------

CMake Warning at cmake/OpenCVPackaging.cmake:23 (message):
  CPACK_PACKAGE_VERSION does not match version provided by version.hpp
  header!
Call Stack (most recent call first):
  CMakeLists.txt:1105 (include)


Configuring done
Generating done

我已经尝试了其他版本的OpenCV,包括最新版本和2.4.7等。每次我都只是构建它,然后在尝试执行编译好的程序后得到相同的错误。我已经尝试指定编译器(我安装了其他版本的mingw),对于gcc使用C:\ mingw \ bin \ gcc.exe,对于g ++使用C:\ mingw \ bin \ g ++.exe。没有成功,还是出现了同样的错误。我尝试安装一个新版本的mingw,并将其放在C:\ mingwnew中,并指定编译器。对于gcc使用C:\ mingwnew \ bin \ gcc.exe,对于g ++使用C:\ mingwnew \ bin \ g ++.exe。但还是没有成功。
生成后,我只需进入c:\ opencv \ build文件夹并键入C:\ mingw \ bin \ mingw32-make.exe(或另一种尝试中的C:\ mingwnew \ bin \ mingw32-make.exe)。有关opencv代码本身的警告(我尝试了一些不同的版本)会出现几个警告。之后,它以没有任何错误的方式结束。我键入C:\ mingw \ bin \ mingw32-make.exe install。之后,我在C:\ opencv \ build \ install \ x86 \ mingw中有一个新文件夹。在C:\ opencv \ build \ install \ x86 \ mingw \ bin中有一些示例,我尝试执行它们。但还是出现了同样的错误。
之后我尝试了以下几件事情:
- 将C:\ opencv \ build \ install \ x86 \ mingw文件夹复制到我的mingw中。将libs和dlls复制到我的项目文件夹目录中(该路径中没有空格),将dlls复制到system32文件夹中。并尝试使用-Wall编译,没有错误,但尝试执行时仍然出现相同的错误。 - 使用以下命令静态编译: c:/ mingw / bin / g ++.exe -Wall -I“C:/ opencv / build / install / include”loadimg.cpp libopencv_core2413.dll.a libopencv_highgui2413.dll.a -o loadimg。 - 使用以下命令编译: c:/ mingw / bin / g ++.exe -Wall -I“C:/ opencv / build / install / include”-L“C:/ opencv / build / install / x86 / mingw / lib”loadimg.cpp -lopencv_core2413 -lopencv_highgui2413 -o loadimg。 - 尝试使用Dependency Walker,但只得到在新操作系统(Windows 10)中使用它时预期的一些错误。我在另一个线程中找到了它,但它没有给我任何线索。 - 尝试使用旧版本OpenCV的预编译二进制文件。但还是出现了同样的错误。 - 尝试使用mingw64,甚至无法编译hello world。似乎它仍然存在许多错误。但我认为mingw32不是问题,因为我以同样的方式使用mingw32编译了其他库(allegro5),并且它可以工作。

我搜索了很多资料,尝试了很多方法,包括使用opencv文档提供的其他示例代码。但是由于我不能安装linux,也无法使用其他电脑,因此这是我唯一的选择。经过数十次构建opencv和两周的时间,我依然无法自己解决错误。

有任何线索或需要更多信息吗?谢谢。


你搞定了吗? - drerD
还没有,我没有放弃尝试解决它。但是我快要放弃了,准备安装一个Linux发行版。 - Nosvan
我将包含dll的bin文件夹添加到环境变量设置中的PATH中,然后总是重新启动我的IDE或终端来运行openCV程序。 - drerD
我不使用集成开发环境,只用Sublime Text和GCC,所以我可能会尝试使用一个。你用什么IDE? - Nosvan
我放弃了,在Python中安装了它。我从OpenCV源代码的build/python文件夹中复制了cv2.pyd文件到site-packages文件夹中,然后它就可以工作了。我成功地使用Python开发。这不是对于这个问题的答案,但对我来说已经足够了。 - Nosvan
显示剩余3条评论
5个回答

7

对于我来说,在OpenCVPackaging.cmake文件中添加OPENCV_VCSVERSION = 2.4.13(使用OpenCV版本2.4.13)是必要的。

#in OpenCVPackaging.cmake file (line 23)
set(OPENCV_VCSVERSION "2.4.13") #<--add
set(CPACK_PACKAGE_VERSION "${OPENCV_VCSVERSION}")

我会尝试一下,谢谢你的回答。到这个阶段,我差点就放弃了。 - Nosvan

2
这个错误在这一行:OpenCV 2.4.13的通用配置。
今天我遇到了这个错误,因为有3.1.0版本,但是http://opencv.org/给出的链接中却是2.4.13版本不匹配。
所以我从这里安装了最新版本,之后就没有出现下面这个错误了。
CMake警告在cmake/OpenCVPackaging.cmake:23 (message)处: CPACK_PACKAGE_VERSION与version.hpp头文件提供的版本不匹配! 调用堆栈(最近的调用在最上面): CMakeLists.txt:1105 (include)
抱歉我的英文不好...

谢谢,我现在会检查它。 - Nosvan
可能需要几个小时来重新编译所有内容,但我会告诉你今天是否有效。 - Nosvan
它没有起作用,我也尝试了官方的Github存储库,但是出现了同样的问题。我相信问题不在编译器、opencv或IDE上。也许是系统上损坏的DLL文件?但我找不到任何线索。 - Nosvan
很不幸,我唯一能提供的额外信息是我使用的是Windows 7和Code::Blocks 16.01。我记得我卸载了OpenCV和Cmake,但我的电脑上仍然有OpenCV和Cmake的文件。我会尝试卸载OpenCV和Cmake,并使用此工具链接搜索您计算机上仍存在的文件,然后使用该工具删除OpenCV和Cmake的残留文件。这个工具可以在您的计算机中搜索任何地方,我使用它的原因是Windows 7内置的搜索引擎真的很差。之后再尝试重新安装Cmake和OpenCV。 - Uwohm9
或许这是 Windows 10 的一个问题。 - Nosvan
但我会尝试你所说的。 - Nosvan

0

如前所述,这是在我们下载代码时发生的,而不是使用git进行克隆。最简单的方法是遵循opencv文档,在编译之前检出所需版本。


0

我现在尝试了一下,但是我在这里遇到了同样的问题,同样的错误信息。 - Nosvan
在OpenCV 2.x中有两个contribs:contrib和nonfree。你是指它们都在opencv_contrib下吗?他们之所以能够实现这一点,是因为专利权的原因吗?因为官方的OpenCV 2.4.13仍然包含opencv_contrib2413.lib、opencv_contrib2413.dll、opencv_nonfree2413.lib和opencv_nonfree2413.dll。 - happy_marmoset
@happy_marmoset 很抱歉我不知道答案。你可能需要发布一个新的StackOverflow问题。 - jkdev

0
我遇到了和你一样的问题。我把MinGW-w64libstdc++-6.dll放到项目目录中,然后它就可以工作了。
解决方案来自这里
实际上,我仍然不明白为什么它能够工作。可能是MinGW-w64中出了些问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接