所以我在C中编写了一个python扩展模块,我正在尝试为我的64位Python构建编译它。在对抗MinGW一段时间之后,我做了一些谷歌搜索,发现MinGW没有做64位扩展模块,所以我设置了Visual C ++ 2008 Express,Win7 SDK和DISTUTILS_USE_SDK和MSSdk都等于1在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天后,在这里碰到了一堵墙,有什么建议吗?
答案 0 :(得分:3)
根据我的经验,除了Visual C ++的完整版本之外,使用Microsoft的任何东西在Windows上构建python模块非常困难。此外,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?,这意味着python是使用Visual C ++ 2008构建的。
对于每个版本的Visual Studio,都有相应版本的Windows SDK,因此如果您想尝试使用免费工具进行此操作,则需要查找并安装正确的 Windows SDK版本。我想那可能是http://www.microsoft.com/en-us/download/details.aspx?id=24826,但我不是百分百肯定。
答案 1 :(得分:0)
我有同样的错误。从https://github.com/nwcell/psycopg2-windows安装psycopg2解决了我的问题
答案 2 :(得分:0)
对于我的情况,改变Visual Studio中的项目属性(构建x64而不是x86的解决方案)有帮助,因为我使用的Python版本是64位。 两个版本都应匹配。
答案 3 :(得分:0)
1,你必须确保python x64,oracle客户端x64(win7 x64),所有版本必须匹配。
2,也许你必须为#python2.7和#34安装vc ++;