为 Python 创建 C++ 扩展 [英] Creating a C++ extension for Python
问题描述
当我按照 创建 C++ 扩展Python 在我到达将 C++ 项目转换为 Python 的扩展部分之前,我没有收到任何错误.
When I follow the instructions from Creating a C++ extension for Python I don't get any errors until I reach the section Convert the C++ project to an extension for Python.
在我完成本节中的步骤并尝试构建解决方案后,我偶然发现了这一点:
After I go through the steps from this section and attempt to build the solution I stumble on this:
1>------ Build started: Project: CppMain, Configuration: Debug Win32 ------
1>module.cpp
1> Creating library C:\Users\$andu\Desktop\Cpp4Py\Debug\Cpp4Py.lib and object C:\Users\$andu\Desktop\Cpp4Py\Debug\Cpp4Py.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:\Python\Anaconda3\libs\python3.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
1>C:\Users\$andu\Desktop\Cpp4Py\Debug\Cpp4Py.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 步.但我真的不知道如何处理.有什么建议吗?
From the message above, I suspect that the problem comes from step 2 in that set of instructions. But I don't really know how to deal with that. Any suggestions?
我使用 x64 Windows 10.
I work with x64 Windows 10.
推荐答案
我不确定.但是您可以将项目的目标机器类型更改为 x64,然后重试.请参阅此警告:
I'm not sure. But you can change your project's target machine type to x64 and try again. See this warning:
C:\Python\Anaconda3\libs\python3.lib:警告 LNK4272:库机器类型x64"与目标机器类型x86"冲突
C:\Python\Anaconda3\libs\python3.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
这篇关于为 Python 创建 C++ 扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!