c++ - 如何在没有 Python 调试库的情况下在 Debug模式下使用 Cmake/Visual Studio 构建 OpenCV

标签 c++ python visual-studio opencv cmake

我正在尝试使用 Visual Studio 2012 (vc11) 在 Windows 7 上从源代码构建 OpenCv 2.4.7。 我有

  • 从 github 下载源代码
  • 切换到 2.4.7 标签
  • 使用cmake配置并生成VS解决方案
  • 在 Release模式和 Debug模式下运行 Win32 的 BUILDALL 目标

在 Release模式下,我可以毫无问题地构建所有内容。 但是,当我尝试构建 Debug模式时,出现以下错误:

Error 2 error LNK1104: cannot open file 'python27_d.lib' C:\Users...\OpenCV\2.4.7\build\modules\python\LINK

我没有python27_d.lib,所以我只是将python27.lib复制到python27_d.lib,希望得到最好的结果,然后重新运行 cmake 配置(可能最后一点毫无意义)。

现在,当我尝试构建时,我收到以下错误:

Error 1 error LNK2019: unresolved external symbol imp_Py_NegativeRefcount referenced in function "struct _object * cdecl pycvCreateHist(struct _object *,struct _object *,struct _object *)" (?pycvCreateHist@@YAPAU_object@@PAU1@00@Z) C:\Users...\OpenCV\2.4.7\build\modules\python\cv2.obj Error 2 error LNK2019: unresolved external symbol __imp_Py_Dealloc referenced in function "struct _object * cdecl pycvCreateHist(struct _object *,struct _object *,struct _object *)" (?pycvCreateHist@@YAPAU_object@@PAU1@00@Z) C:\Users...\OpenCV\2.4.7\build\modules\python\cv2.obj Error 3 error LNK2019: unresolved external symbol __imp_PyObject_DebugMalloc referenced in function "struct _object * cdecl pyopencv_VideoCapture_VideoCapture(struct _object *,struct _object *,struct _object *)" (?pyopencv_VideoCapture_VideoCapture@@YAPAU_object@@PAU1@00@Z) C:\Users...\OpenCV\2.4.7\build\modules\python\cv2.obj Error 4 error LNK2019: unresolved external symbol __imp_PyObject_DebugFree referenced in function "void cdecl Capture_dealloc(struct _object *)" (?Capture_dealloc@@YAXPAU_object@@@Z) C:\Users...\OpenCV\2.4.7\build\modules\python\cv2.obj Error 5 error LNK2019: unresolved external symbol _imp_Py_InitModule4TraceRefs referenced in function "struct _object * __cdecl init_cv(void)" (?init_cv@@YAPAU_object@@XZ) C:\Users...\OpenCV\2.4.7\build\modules\python\cv2.obj Error 6 error LNK2001: unresolved external symbol __imp_Py_RefTotal C:\Users...\OpenCV\2.4.7\build\modules\python\cv2.obj Error 7 error LNK1120: 6 unresolved externals C:\Users...\OpenCV\2.4.7\build\lib\Debug\cv2.pyd

除了下载Python的源代码并对其进行调试构建,以便我有一个合适的python27_d.lib(我认为我没有其他需要),关于如何解决的任何想法这个?

最佳答案

根据OpenCv网站的说法,在使用CMake后,您需要将Visual Studio项目切换到发布版本。 http://docs.opencv.org/3.1.0/d5/de5/tutorial_py_setup_in_windows.html

这可以通过右键单击解决方案并单击配置管理器来访问此设置来完成。

我已经使用 Visual Studio 2015 Community、OpenCV 3.2.0 和 python 3.6 (Anaconda) 对此进行了测试

关于c++ - 如何在没有 Python 调试库的情况下在 Debug模式下使用 Cmake/Visual Studio 构建 OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20094101/

相关文章:

visual-studio - Visual Studio和多个合并/比较工具

asp.net - "Invalid attempt to read when no data is present"

c++ - 工业级n吨基类模板

c++ - std::vector 保留方法无法分配足够的内存

python - 打印二叉树

python - PyQt中如何调用多个Dialog?

c++ - 拼接图片检测不到共同特征点

C++0x : overloading on lambda arity

C++:数组元素设置为 0

python - django.core.exceptions.ImproperlyConfigured : Field name `id` is not valid for model