简体   繁体   English

为Python创建C ++扩展

[英]Creating a C++ extension for 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 . 当我按照“ 为Python创建C ++扩展”中的说明进行操作时,直到到达“ 将C ++项目转换 为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 ==========

From the message above, I suspect that the problem comes from step 2 in that set of instructions. 从上面的消息中,我怀疑问题出在该指令集中的步骤2。 But I don't really know how to deal with that. 但是我真的不知道该如何处理。 Any suggestions? 有什么建议么?


I work with x64 Windows 10. 我使用x64 Windows 10。

I'm not sure. 我不确定。 But you can change your project's target machine type to x64 and try again. 但是您可以将项目的目标计算机类型更改为x64,然后重试。 See this warning: 看到以下警告:

C:\\Python\\Anaconda3\\libs\\python3.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86' C:\\ Python \\ Anaconda3 \\ libs \\ python3.lib:警告LNK4272:库机器类型'x64'与目标机器类型'x86'发生冲突

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM