首页 文章

如何在没有Python调试库的调试模式下使用Cmake / Visual Studio构建OpenCV

提问于
浏览
1

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

  • 从github下载了源代码

  • 切换到2.4.7标签

  • 使用cmake配置和生成VS解决方案

  • 在发布模式和调试模式下运行Win32的BUILDALL目标

在发布模式下,我可以毫无问题地构建所有内容 . 但是,当我尝试构建调试模式时,我收到以下错误:

错误2错误LNK1104:无法打开文件'python27_d.lib'C:\ Users ... \ OpenCV \ 2.4.7 \ build \ modules \ python \ LINK

我没有 python27_d.lib ,所以我只是简单地将 python27.lib 复制到 python27_d.lib ,希望是最好的,并重新启动cmake配置(可能最后一点毫无意义) .

现在当我尝试构建时,我得到了这些错误:

错误1错误LNK2019:未解析的外部符号imp_Py_NegativeRefcount在函数“struct _object * cdecl pycvCreateHist(struct _object *,struct _object *,struct _object *)”中引用(?pycvCreateHist @@ YAPAU_object @@ PAU1 @ 00 @ Z)C:\用户... \ OpenCV \ 2.4.7 \ build \ modules \ python \ cv2.obj错误2错误LNK2019:函数“struct _object * cdecl pycvCreateHist”中引用的未解析的外部符号__imp_Py_Dealloc(struct _object *,struct _object *,struct _object * )“(?pycvCreateHist @@ YAPAU_object @@ PAU1 @00 @ Z)C:\ Users ... \ OpenCV \ 2.4.7 \ build \ modules \ python \ cv2.obj错误3错误LNK2019:未解析的外部符号__imp_PyObject_DebugMalloc在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错误4错误LNK2019:未解析的外部符号__imp_PyObject_DebugFree在函数中引用“void cdecl Capture_dealloc(struct _object *)“(?Capture_dealloc @@ YAXPAU_object @@@ Z)C:\ Users ... \ OpenCV \ 2.4.7 \ build \ modules \ python \ cv2.obj错误5错误LNK2019:未解析的外部符号_imp_Py_InitModule4TraceRefs在函数“struct _object * __cdecl init_cv(void)”中引用(?init_cv @@ YAPAU_object @@ XZ)C:\ Users ... \ OpenCV \ 2.4.7 \ build \ modules \ python \ cv2.obj错误6错误LNK2001:未解析的外部符号__imp_Py_RefTotal C:\ Users ... \ OpenCV \ 2.4.7 \ build \ modules \ python \ cv2.obj错误7错误LNK1120:6个未解析的外部C:\ Users ... \ OpenCV \ 2.4.7 \编译\ LIB \调试\ cv2.pyd

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

2 回答

  • 2

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

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

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

  • 0

    找到pyconfig.h的变化

    #ifdef _DEBUG 
    # define Py_DEBUG 
    #endif
    

    #ifdef _DEBUG 
    //# define Py_DEBUG 
    #endif
    

    chagne

    # ifdef _DEBUG 
    # pragma comment(lib,"python27_d.lib") 
    # else 
    # pragma comment(lib,"python27.lib") 
    # endif /* _DEBUG */
    

    # ifdef _DEBUG 
    # pragma comment(lib,"python27.lib") 
    # else 
    # pragma comment(lib,"python27.lib") 
    # endif /* _DEBUG */
    

    修改object.h

    #if defined(Py_DEBUG) && !defined(Py_TRACE_REFS) 
    #define Py_TRACE_REFS 
    #endif
    

    #if defined(Py_DEBUG) && !defined(Py_TRACE_REFS) 
    // #define Py_TRACE_REFS 
    #endif
    

相关问题