无法打开文件“python310_d.lib”,获取Python Debug 库。
问题原因:
-
Python Debug 库缺失:
- 默认情况下,标准 Python 安装(例如 Anaconda)不会附带 Debug 版本的库文件(
python310_d.lib
)。 - 在 Debug 模式下运行 C++ 程序时,MSVC(Microsoft Visual C++ 编译器)会尝试链接带有
_d
后缀的 Python 库(即 Debug 版本),但这个文件通常不存在。 - 如果你配置了 Debug 模式,CMake 会假定需要链接
python310_d.lib
。 - 而你实际使用的是 Release 版本的 Python 库(
python310.lib
),导致链接器无法找到对应的 Debug 库。
2.获取_d.lib
生成 Debug 版本库的步骤
1. 下载 Python 源码
正确运行输出:
Initializing Python…
Python initialized successfully.
Importing Python module…
Python module imported successfully.
Calling Python function…
Hello from Python!
Python finalized.
作者:kamisama_zhu