【问题标题】:Problem Extending Python(Linking Error )?扩展 Python 的问题(链接错误)?
【发布时间】:2009-03-21 08:23:00
【问题描述】:

我已经安装了 Python 3k(C:\Python30) 和 Visual Studio Professional Edition 2008。

我正在学习this

这里有个问题:

C:\hello>dir
 Volume in drive C has no label.
 Volume Serial Number is 309E-14FB

 Directory of C:\hello

03/21/2009  01:15 AM    <DIR>          .
03/21/2009  01:15 AM    <DIR>          ..
03/21/2009  01:14 AM               481 hellomodule.c
               1 File(s)            481 bytes
               2 Dir(s)  10,640,642,048 bytes free


C:\hello>cl /LD hellomodule.c /Ic:\Python30\include c:\Python30\libs\python30.lib /link/out:hello.
dll
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

hellomodule.c
c:\hello\hellomodule.c(26) : warning C4716: 'inithello' : must return a value
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:hellomodule.dll
/dll
/implib:hellomodule.lib
/out:hello.dll
hellomodule.obj
c:\Python30\libs\python30.lib
   Creating library hellomodule.lib and object hellomodule.exp
hellomodule.obj : error LNK2019: unresolved external symbol _Py_InitModule referenced in function
_inithello
hello.dll : fatal error LNK1120: 1 unresolved externals

C:\hello>

有什么问题?请指导我。

【问题讨论】:

标签: python c visual-studio visual-studio-2008 linker


【解决方案1】:

如果c:\python30中安装了Python,为什么要搜索c:\Python24\libs\python30中的库?

现在您已经更改了问题来解决这个问题:-),

我认为Py_InitModule 不再可用,您必须使用PyModule_Create(这可能在我最后一次查看Py3k 的早期测试版之后发生了变化)。

David,根据您的 cmets,我建议您避免使用官方 Python 文档之外的 HowTo 网站(我怀疑它们已经过时了)。在 3.0 级别的扩展界面上发生了很多工作,最好的地方是 在3.0 docs3.1 alpha docs

具体的 Windows 构建说明为here

【讨论】:

  • 酷,它生成了 hello.dll,现在,我应该如何导入它?(我试过 import hello)。但是说没有名为 hello 的模块。
  • 注意:我刚刚用 PyModule_Create 替换了 Py_InitModule。这样可以吗?或者我还需要什么。
猜你喜欢
  • 1970-01-01
  • 2012-09-17
  • 2018-12-09
  • 1970-01-01
  • 2022-01-05
  • 1970-01-01
  • 2020-09-07
  • 2011-09-01
  • 2022-06-13
相关资源
最近更新 更多