2012-09-25 35 views
3

所以我在C编写一个python扩展模块,我试图编译它为我的64位Python版本。在对MinGW进行了一段时间的抨击之后,我做了一些搜索,发现MinGW不会执行64位扩展模块,所以我使用Win7 SDK和DISTUTILS_USE_SDK和MSSdk设置了Visual C++ 2008 Express,它们都等于1在this question的答案。编译python扩展模块时链接错误

我终于Distutils的找到编译器,但是当我编译扩展我得到这样的输出:

core.obj : error LNK2019: unresolved external symbol __imp__PyErr_NoMemory refer 
enced in function "int __cdecl handleErrors(int)" ([email protected]@[email protected]) 
core.obj : error LNK2019: unresolved external symbol __imp__PyErr_SetString refe 
renced in function "int __cdecl handleErrors(int)" ([email protected]@[email protected]) 
core.obj : error LNK2019: unresolved external symbol _opus_encoder_destroy refer 
enced in function "void __cdecl OpusEncoder_dealloc(struct OpusEncoderObject *)" 
([email protected]@[email protected]@@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 *)" ([email protected]@[email protected]@PAU_o 
[email protected]@[email protected]) 
core.obj : error LNK2019: unresolved external symbol _opus_encoder_create refere 
nced in function "int __cdecl OpusEncoder_init(struct OpusEncoderObject *,struct 
_object *,struct _object *)" ([email protected]@[email protected]@PAU_o 
[email protected]@[email protected]) 
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 *)" ([email protected]@YAHPAUOpusEncode 
[email protected]@[email protected]@[email protected]) 
core.obj : error LNK2019: unresolved external symbol __imp__PyTuple_Pack referen 
ced in function "struct _object * __cdecl OpusEncoder_encode(struct OpusEncoderO 
bject *,struct _object *)" ([email protected]@[email protected]@PAUOpusEncoderObj 
[email protected]@[email protected]@Z) 
core.obj : error LNK2019: unresolved external symbol __imp__PyString_FromString 
referenced in function "struct _object * __cdecl OpusEncoder_encode(struct OpusE 
ncoderObject *,struct _object *)" ([email protected]@[email protected]@PAUOpusEnc 
[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@PAUOpusEncoderObje 
[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@PAUOpusEncode 
[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@PAUOpusEncode 
[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@PAUOpusEncoderObj 
[email protected]@[email protected]@Z) 
core.obj : error LNK2019: unresolved external symbol _opus_encode referenced in 
function "struct _object * __cdecl OpusEncoder_encode(struct OpusEncoderObject * 
,struct _object *)" ([email protected]@[email protected]@[email protected]@PA 
[email protected]@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 *)" ([email protected]@[email protected]@PAUOpusEncoderO 
[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@PAUOpusEncoderObj 
[email protected]@[email protected]@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 *)" ([email protected]@[email protected]@PAUOpusEncode 
[email protected]@[email protected]@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天,之后在这里碰了壁,任何建议?

回答

3

根据我的经验,在Windows上使用任何来自Microsoft的任何内容构建python模块非常困难,除了完整的版本的Visual C++。此外,Visual Studio的版本必须匹配用于构建您的python发行版的版本。

例如,与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 
... 

What version of Visual Studio is Python on my computer compiled with?,这意味着蟒蛇是用Visual C++ 2008

建成对于Visual Studio的每个版本,则有相应版本的Windows SDK,因此如果您想尝试使用免费工具进行此项工作,则需要查找并安装正确的 Windows SDK版本。我认为这可能是http://www.microsoft.com/en-us/download/details.aspx?id=24826,但我不是100%确定的。

+0

我实际上已经与SDK编译,链接器错误是完全独立的。 – glittershark

0

对于我而言,改变了Visual Studio中的项目属性(为x64而不是x86构建解决方案)有所帮助,因为我使用的Python版本是64位。 两个版本都应匹配。

0

1,您必须确保python x64,oracle客户端x64(win7 x64),所有版本必须匹配。

2,也许你不得不“装VC++的python2.7”