错误问题详情
解决方法
原因: 这是因为使用的 python 是 Release 版,而编译是在 Debug 模式下编译的(Release 模式下没有此问题)
在 python 的安装位置找到 include
文件夹,在文件夹下找到 pyconfig.h
文件
因为我用的是anaconda3装的,所以我的 pyconfig.h
位置为 D:\Programs\anaconda3\include\pyconfig.h
将 comment(lib,"python38_d.lib")
改为 comment(lib,"python38.lib")
修改前:
/* For an MSVC DLL, we can nominate the .lib files used by extensions */
#ifdef MS_COREDLL
# if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
/* 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.) */
# if defined(_DEBUG)
# pragma comment(lib,"python38_d.lib")
# elif defined(Py_LIMITED_API)
# pragma comment(lib,"python3.lib")
# else
# pragma comment(lib,"python38.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
# if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
/* 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.) */
# if defined(_DEBUG)
# pragma comment(lib,"python38.lib")
# elif defined(Py_LIMITED_API)
# pragma comment(lib,"python3.lib")
# else
# pragma comment(lib,"python38.lib")
# endif /* _DEBUG */
# endif /* _MSC_VER */
# endif /* Py_BUILD_CORE */
#endif /* MS_COREDLL */
如图所示:
修改前:
修改后:
相关问题
LNK2019 无法解析的外部符号 __imp__Py_NegativeRefcount、__imp_Py_RefTotal 问题
解决办法请看:
Visual Studio 2019 重新生成 OpenCV 解决方案报 LNK2019 无法解析的外部符号 __imp__Py_NegativeRefcount、__imp_Py_RefTotal