錯誤 24 error LNK1104: 無法打開文件“python27_d.lib” C:\OpenCV\VS2013_64\modules\python\LINK opencv_python
編譯環境概述:
1、IDE:Visual Studio C++2010,debug win32;
2、OpenCV版本:opencv-2.4.4.tar.gz(源代碼);
3、CMake版本:cmake-2.8.8-win32-x86.exe。
方法1:
錯誤的原因是系統安裝有Python2.7,而默認的情況下Python是不提供python27_d.lib和python27_d.dll文件的。為了編譯通過,需要在網上下載此二文件。下載地址請點擊這里。
將下載的lib文件置於C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib,dll文件置於C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin,編譯通過。
方法2:
一個妥協的方法是注釋掉會使用python27_d.lib部分的代碼,替換為使用python27.lib
具體做法如下:
在OpenCV項目的bindings中的opencv_python項目中,點擊“外部依賴項”,在其中找到pyconfig.h和object.h文件,如下圖所示:

在pyconfig.h中,將
#ifdef _DEBUG # define Py_DEBUG #endif
修改為:
#ifdef _DEBUG //# define Py_DEBUG #endif
將
/* For an MSVC DLL, we can nominate the .lib files used by extensions */ #ifdef MS_COREDLL # ifndef Py_BUILD_CORE /* not building the core - must be an ext */ # if defined(_MSC_VER) /* So MSVC users need not specify the .lib file in their Makefile (other compilers are generally taken care of by distutils.) */ # ifdef _DEBUG # pragma comment(lib,"python27_d.lib") # else # pragma comment(lib,"python27.lib") # endif /* _DEBUG */ # endif /* _MSC_VER */ # endif /* Py_BUILD_CORE */ #endif /* MS_COREDLL */
修改為
/* For an MSVC DLL, we can nominate the .lib files used by extensions */ #ifdef MS_COREDLL # ifndef Py_BUILD_CORE /* not building the core - must be an ext */ # if defined(_MSC_VER) /* So MSVC users need not specify the .lib file in their Makefile (other compilers are generally taken care of by distutils.) */ # ifdef _DEBUG # pragma comment(lib,"python27.lib") # else # pragma comment(lib,"python27.lib") # endif /* _DEBUG */ # endif /* _MSC_VER */ # endif /* Py_BUILD_CORE */ #endif /* MS_COREDLL */
在object.h中,將
/* Py_DEBUG implies Py_TRACE_REFS. */ #if defined(Py_DEBUG) && !defined(Py_TRACE_REFS) #define Py_TRACE_REFS #endif
修改為
/* Py_DEBUG implies Py_TRACE_REFS. */ #if defined(Py_DEBUG) && !defined(Py_TRACE_REFS) //#define Py_TRACE_REFS #endif
保存之后,再次編譯就成功啦!
參考鏈接:
