win10下用 Visual Studio 2019 重新生成 OpenCV 解决方案报 LNK1104 无法打开文件 “python38_d.lib”

在这里插入图片描述解决方法

原因: 这是因为使用的 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 */

修改完后又报错:
在这里插入图片描述解决方法

原因: 这是因为使用的 python 是 Release 版,而编译是在 Debug 模式下编译的(Release 模式下没有此问题)

在 python 的安装位置找到 include 文件夹,在文件夹下找到 pyconfig.h 、object.h 文件
因为我用的是 anaconda3 装的,所以
我的 pyconfig.h 位置为 D:\Programs\anaconda3\include\pyconfig.h
我的 object.h 位置为 D:\Programs\anaconda3\include\object.h

修改 pyconfig.h

注释 # define Py_DEBUG

修改前:

#ifdef _DEBUG
#       define Py_DEBUG
#endif

修改后

#ifdef _DEBUG
#       define Py_DEBUG
#endif

修改 object.h

注释 #define Py_REF_DEBUG

修改前:

/* Py_DEBUG implies Py_REF_DEBUG. */
#if defined(Py_DEBUG) && !defined(Py_REF_DEBUG)
#define Py_REF_DEBUG
#endif

修改后

/* Py_DEBUG implies Py_REF_DEBUG. */
#if defined(Py_DEBUG) && !defined(Py_REF_DEBUG)
//#define Py_REF_DEBUG
#endif

参考这位大佬的:https://blog.csdn.net/ZChen1996/article/details/115998472

  • 4
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值