编译python扩展模块时链接错误 [英] Linking errors when compiling python extension module
问题描述
因此,我正在用C语言编写一个python扩展模块,并且试图为我的64位Python构建对其进行编译.在抵制MinGW一段时间后,我进行了一些谷歌搜索,发现MinGW不执行64位扩展模块,因此我使用Win7 SDK设置了Visual C ++ 2008 Express,并且DISTUTILS_USE_SDK和MSSdk都等于1.在此问题的答案中.
So I'm writing a python extension module in C and I'm trying to compile it for my 64-bit Python build. After bashing my head against MinGW for a while, I did some googling around and found that MinGW doesn't do 64-bit extension modules, so I set up Visual C++ 2008 Express with the Win7 SDK and DISTUTILS_USE_SDK and MSSdk both equal to 1 as in the answers to this question.
我终于让Distutils找到了编译器,但是当我编译扩展时,我得到了以下输出:
I finally got Distutils to find the compilers, but when I compile the extension I get this output:
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
用力撞了三天后,我有点撞墙了,有什么建议吗?
I've kinda hit a wall here after banging my head against this for 3 days, any advice?
推荐答案
以我的经验,除了Visual C ++的 full 版本外,很难使用Microsoft的任何东西在Windows上构建python模块.此外,Visual Studio的版本必须匹配用于构建python发行版的版本.
In my experience, it's very difficult to build python modules on windows with anything from Microsoft except the full version of Visual C++. Further, the version of Visual Studio must match the version that was used to build your python distribution.
例如,使用Python 2.7.1的官方二进制发行版:
For example, with the official binary dist of Python 2.7.1:
C:\Python27>python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
...
根据什么版本的Visual Studio是Python在使用?编译的计算机上?,这意味着python是使用Visual C ++ 2008构建的.
According to What version of Visual Studio is Python on my computer compiled with?, that means that python was built with Visual C++ 2008.
对于每个版本的Visual Studio,都有一个对应的Windows SDK版本,因此,如果您想尝试使用免费工具来工作,则需要查找并安装正确 Windows SDK版本.我认为可能是 http://www.microsoft.com /en-us/download/details.aspx?id=24826 ,但我不确定100%.
For each version of Visual Studio, there is a corresponding version of the Windows SDK, so if you want to try to make this work with free tools, you need to find and install the correct Windows SDK version. I think that might be http://www.microsoft.com/en-us/download/details.aspx?id=24826, but I'm not 100% sure.
这篇关于编译python扩展模块时链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!