Reputation: 11941
I am trying to build OpenCv 2.4.7 from source on Windows 7 using Visual Studio 2012 (vc11). I have
In release mode, I can build all with no problem . However, when I attempt to build for debug mode I get the following error:
Error 2 error LNK1104: cannot open file 'python27_d.lib' C:\Users...\OpenCV\2.4.7\build\modules\python\LINK
I don't have a python27_d.lib
, so I simply copied python27.lib
to python27_d.lib
, hoped for the best, and reran the cmake configuration (probably that last bit was pointless).
Now when I attempt to build I get these errors:
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
Other than downloading the source for Python and making a debug build of it so I have a proper python27_d.lib
(of which I think I have no other need), any ideas on how to solve this?
Upvotes: 2
Views: 6000
Reputation: 11
find the pyconfig.h change
#ifdef _DEBUG
# define Py_DEBUG
#endif
to
#ifdef _DEBUG
//# define Py_DEBUG
#endif
chagne
# ifdef _DEBUG
# pragma comment(lib,"python27_d.lib")
# else
# pragma comment(lib,"python27.lib")
# endif /* _DEBUG */
to
# ifdef _DEBUG
# pragma comment(lib,"python27.lib")
# else
# pragma comment(lib,"python27.lib")
# endif /* _DEBUG */
modify object.h
#if defined(Py_DEBUG) && !defined(Py_TRACE_REFS)
#define Py_TRACE_REFS
#endif
to
#if defined(Py_DEBUG) && !defined(Py_TRACE_REFS)
// #define Py_TRACE_REFS
#endif
Upvotes: 1
Reputation: 194
According to the OpenCv website you need to switch the Visual Studio project to release after you have used CMake. http://docs.opencv.org/3.1.0/d5/de5/tutorial_py_setup_in_windows.html
This can be done by right clicking the solution and clicking configuration manager to access this setting.
I have tested this with Visual Studio 2015 Community, OpenCV 3.2.0 and python 3.6 (Anaconda)
Upvotes: 2