gpt4 book ai didi

python - 编译python扩展模块时链接错误

转载 作者:行者123 更新时间:2023-11-28 16:47:13 26 4
gpt4 key购买 nike

所以我正在用 C 语言编写一个 python 扩展模块,并尝试为我的 64 位 Python 构建编译它。在对 MinGW 进行了一段时间的抨击之后,我进行了一些谷歌搜索,发现 MinGW 不支持 64 位扩展模块,因此我使用 Win7 SDK 和 DISTUTILS_USE_SDK 以及 MSSdk 都等于 1 设置了 Visual C++ 2008 Express在 this question 的答案中.

我终于让 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

我用头撞了 3 天后有点碰壁了,有什么建议吗?

最佳答案

根据我的经验,除了 完整 版的 Visual C++ 外,很难使用 Microsoft 的任何软件在 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开发工具包版本。我想那可能是 http://www.microsoft.com/en-us/download/details.aspx?id=24826 ,但我不是 100% 确定。

关于python - 编译python扩展模块时链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12589617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com