编译python扩展modu时的链接错误

2024-09-28 17:15:57 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我用C编写了一个python扩展模块,并试图为我的64位python构建编译它。在我的头撞了MinGW一段时间后,我做了一些搜索,发现MIWW不做64位扩展模块,所以我用Wi7SDK和DItStudisIUsSDK和MSDK都设置了VisualC++ 2008的Express,这两个表达式都等于1,如在{{A1}的答案中一样。

我终于找到了Distutils来查找编译器,但是当我编译扩展时,得到了以下输出:

core.obj : error LNK2019: unresolved external symbol __imp__PyErr_NoMemory refer
enced in function "int __cdecl handleErrors(int)" (?handleErrors@@YAHH@Z)
core.obj : error LNK2019: unresolved external symbol __imp__PyErr_SetString refe
renced in function "int __cdecl handleErrors(int)" (?handleErrors@@YAHH@Z)
core.obj : error LNK2019: unresolved external symbol _opus_encoder_destroy refer
enced in function "void __cdecl OpusEncoder_dealloc(struct OpusEncoderObject *)"
 (?OpusEncoder_dealloc@@YAXPAUOpusEncoderObject@@@Z)
core.obj : error LNK2019: unresolved external symbol __imp__Py_BuildValue refere
nced in function "int __cdecl OpusEncoder_init(struct OpusEncoderObject *,struct
 _object *,struct _object *)" (?OpusEncoder_init@@YAHPAUOpusEncoderObject@@PAU_o
bject@@1@Z)
core.obj : error LNK2019: unresolved external symbol _opus_encoder_create refere
nced in function "int __cdecl OpusEncoder_init(struct OpusEncoderObject *,struct
 _object *,struct _object *)" (?OpusEncoder_init@@YAHPAUOpusEncoderObject@@PAU_o
bject@@1@Z)
core.obj : error LNK2019: unresolved external symbol __imp__PyArg_ParseTupleAndK
eywords referenced in function "int __cdecl OpusEncoder_init(struct OpusEncoderO
bject *,struct _object *,struct _object *)" (?OpusEncoder_init@@YAHPAUOpusEncode
rObject@@PAU_object@@1@Z)
core.obj : error LNK2019: unresolved external symbol __imp__PyTuple_Pack referen
ced in function "struct _object * __cdecl OpusEncoder_encode(struct OpusEncoderO
bject *,struct _object *)" (?OpusEncoder_encode@@YAPAU_object@@PAUOpusEncoderObj
ect@@PAU1@@Z)
core.obj : error LNK2019: unresolved external symbol __imp__PyString_FromString
referenced in function "struct _object * __cdecl OpusEncoder_encode(struct OpusE
ncoderObject *,struct _object *)" (?OpusEncoder_encode@@YAPAU_object@@PAUOpusEnc
oderObject@@PAU1@@Z)
core.obj : error LNK2019: unresolved external symbol _opus_encode_float referenc
ed in function "struct _object * __cdecl OpusEncoder_encode(struct OpusEncoderOb
ject *,struct _object *)" (?OpusEncoder_encode@@YAPAU_object@@PAUOpusEncoderObje
ct@@PAU1@@Z)
core.obj : error LNK2019: unresolved external symbol __imp__PyFloat_AsDouble ref
erenced in function "struct _object * __cdecl OpusEncoder_encode(struct OpusEnco
derObject *,struct _object *)" (?OpusEncoder_encode@@YAPAU_object@@PAUOpusEncode
rObject@@PAU1@@Z)
core.obj : error LNK2019: unresolved external symbol __imp__PyType_IsSubtype ref
erenced in function "struct _object * __cdecl OpusEncoder_encode(struct OpusEnco
derObject *,struct _object *)" (?OpusEncoder_encode@@YAPAU_object@@PAUOpusEncode
rObject@@PAU1@@Z)
core.obj : error LNK2019: unresolved external symbol __imp__PyFloat_Type referen
ced in function "struct _object * __cdecl OpusEncoder_encode(struct OpusEncoderO
bject *,struct _object *)" (?OpusEncoder_encode@@YAPAU_object@@PAUOpusEncoderObj
ect@@PAU1@@Z)
core.obj : error LNK2019: unresolved external symbol _opus_encode referenced in
function "struct _object * __cdecl OpusEncoder_encode(struct OpusEncoderObject *
,struct _object *)" (?OpusEncoder_encode@@YAPAU_object@@PAUOpusEncoderObject@@PA
U1@@Z)
core.obj : error LNK2019: unresolved external symbol __imp__PyErr_Occurred refer
enced in function "struct _object * __cdecl OpusEncoder_encode(struct OpusEncode
rObject *,struct _object *)" (?OpusEncoder_encode@@YAPAU_object@@PAUOpusEncoderO
bject@@PAU1@@Z)
core.obj : error LNK2019: unresolved external symbol __imp__PyInt_AsLong referen
ced in function "struct _object * __cdecl OpusEncoder_encode(struct OpusEncoderO
bject *,struct _object *)" (?OpusEncoder_encode@@YAPAU_object@@PAUOpusEncoderObj
ect@@PAU1@@Z)
core.obj : error LNK2019: unresolved external symbol __imp__PyArg_ParseTuple ref
erenced in function "struct _object * __cdecl OpusEncoder_encode(struct OpusEnco
derObject *,struct _object *)" (?OpusEncoder_encode@@YAPAU_object@@PAUOpusEncode
rObject@@PAU1@@Z)
core.obj : error LNK2019: unresolved external symbol __imp__PyModule_AddObject r
eferenced in function _initopys
core.obj : error LNK2019: unresolved external symbol __imp__PyErr_NewException r
eferenced in function _initopys
core.obj : error LNK2019: unresolved external symbol __imp__Py_InitModule4 refer
enced in function _initopys
core.obj : error LNK2019: unresolved external symbol __imp__PyType_Ready referen
ced in function _initopys
core.obj : error LNK2019: unresolved external symbol __imp__PyType_GenericNew re
ferenced in function _initopys
core.obj : error LNK2019: unresolved external symbol __imp__Py_Initialize refere
nced in function _main
core.obj : error LNK2019: unresolved external symbol __imp__Py_SetProgramName re
ferenced in function _main
build\lib.win-amd64-2.7\opys.pyd : fatal error LNK1120: 23 unresolved externals
error: command '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.
exe"' failed with exit status 1120

我头撞了三天的墙,有什么建议吗?


Tags: incoreobjobjectfunctionerrorsymbolstruct
3条回答

我也犯了同样的错误。从https://github.com/nwcell/psycopg2-windows安装psycopg2解决了我的问题

在我的经验中,除了C++的EM>完全ESE>版本之外,在Windows上用微软的任何东西都很难构建Python模块。此外,Visual Studio的版本必须与用来构建python发行版的版本相匹配。

例如,对于Python 2.7.1的官方二进制dist:

C:\Python27>python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
...
<^ >根据What version of Visual Studio is Python on my computer compiled with?,这意味着Python是用Visual C++ 2008构建的。

对于每个版本的Visual Studio,都有一个对应的Windows SDK版本,因此如果您想使用免费工具来实现这一点,您需要找到并安装正确的Windows SDK版本。我想可能是http://www.microsoft.com/en-us/download/details.aspx?id=24826,但我不是百分之百确定。

对我来说,在Visual studio中更改项目属性(为x64而不是x86构建解决方案)是有帮助的,因为我使用的Python版本是64位的。 两个版本应匹配。

相关问题 更多 >