为Python创建C 扩展

Creating a C++ extension for Python

本文关键字:扩展 创建 Python      更新时间:2023-10-16

当我按照创建python创建C 扩展的指令时,我不会遇到任何错误>。

我经过本节的步骤并尝试构建解决方案,我偶然发现了这一点:

1>------ Build started: Project: CppMain, Configuration: Debug Win32 ------
1>module.cpp
1>   Creating library C:Users$anduDesktopCpp4PyDebugCpp4Py.lib and object C:Users$anduDesktopCpp4PyDebugCpp4Py.exp
1>module.obj : error LNK2019: unresolved external symbol __imp__PyFloat_FromDouble referenced in function "struct _object * __cdecl tanh(struct _object *,struct _object *)" (?tanh@@YAPAU_object@@PAU1@0@Z)
1>module.obj : error LNK2019: unresolved external symbol __imp__PyFloat_AsDouble referenced in function "struct _object * __cdecl tanh(struct _object *,struct _object *)" (?tanh@@YAPAU_object@@PAU1@0@Z)
1>module.obj : error LNK2019: unresolved external symbol __imp__PyModule_Create2 referenced in function _PyInit_Cpp4Py
1>C:PythonAnaconda3libspython3.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
1>C:Users$anduDesktopCpp4PyDebugCpp4Py.pyd : fatal error LNK1120: 3 unresolved externals
1>Done building project "CppMain.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

从上面的消息中,我怀疑问题来自该指令中的步骤2。但是我真的不知道该如何处理。有什么建议吗?


我与X64 Windows 10一起工作。

我不确定。但是您可以将项目的目标机类型更改为X64,然后重试。请参阅此警告:

c: python anaconda3 libs python3.lib:警告lnk4272:库机器类型'x64'与目标机器类型'x86'

冲突