2011-01-21 120 views
1

我已经在作者website上发布了这个问题,但我想我也可以在这里问。安装/编译pylzma(lzma python binding)

我一直在试图用此安装程序安装pylzma:

  • Windows 7的64位
  • 的Python 2.6.6 64
  • AMD64位编译器从Windows Server 2003来SDK
  • 克隆混帐混帐回购://github.com/fancycode/pylzma.git

用一个简单的easy_install pylzma我得到这个:

cl : Command line warning D9025 : overriding '/MD' with '/MT' pylzma.c src/pylzma/pylzma.c(85) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data

src/pylzma/pylzma.c(102) : error C2275: 'CSha256' : illegal use of this type as an expression c:\users\xavier.lapointe\appdata\local\temp\easy_install-2mfkqu\pylzma-0.4.3\src\pylzma../7zip/C/Sha256.h(18) : see declaration of 'CSha256'

src/pylzma/pylzma.c(102) : error C2146: syntax error : missing ';' before identifier 'sha'

src/pylzma/pylzma.c(102) : error C2065: 'sha' : undeclared identifier

src/pylzma/pylzma.c(103) : error C2065: 'sha' : undeclared identifier

src/pylzma/pylzma.c(103) : warning C4133: 'function' : incompatible types - from 'int *' to 'CSha256 *'

src/pylzma/pylzma.c(104) : error C2143: syntax error : missing ';' before 'type'

src/pylzma/pylzma.c(105) : error C2143: syntax error : missing ';' before 'type'

src/pylzma/pylzma.c(106) : error C2143: syntax error : missing ';' before 'type'

src/pylzma/pylzma.c(107) : error C2143: syntax error : missing ';' before 'type'

src/pylzma/pylzma.c(108) : error C2065: 'round' : undeclared identifier

src/pylzma/pylzma.c(108) : error C2065: 'round' : undeclared identifier

src/pylzma/pylzma.c(108) : error C2065: 'rounds' : undeclared identifier

src/pylzma/pylzma.c(108) : error C2065: 'round' : undeclared identifier

src/pylzma/pylzma.c(109) : error C2065: 'sha' : undeclared identifier

src/pylzma/pylzma.c(109) : warning C4133: 'function' : incompatible types - from 'int *' to 'CSha256 *'

src/pylzma/pylzma.c(110) : error C2065: 'sha' : undeclared identifier

src/pylzma/pylzma.c(110) : warning C4133: 'function' : incompatible types - from 'int *' to 'CSha256 *'

src/pylzma/pylzma.c(111) : error C2065: 'sha' : undeclared identifier

src/pylzma/pylzma.c(111) : warning C4133: 'function' : incompatible types - from 'int *' to 'CSha256 *'

src/pylzma/pylzma.c(111) : error C2065: 'temp' : undeclared identifier

src/pylzma/pylzma.c(112) : error C2065: 'i' : undeclared identifier

src/pylzma/pylzma.c(112) : error C2065: 'i' : undeclared identifier

src/pylzma/pylzma.c(112) : error C2065: 'i' : undeclared identifier

src/pylzma/pylzma.c(113) : error C2065: 'temp' : undeclared identifier

src/pylzma/pylzma.c(113) : error C2065: 'i' : undeclared identifier

src/pylzma/pylzma.c(113) : error C2109: subscript requires array or pointer type

src/pylzma/pylzma.c(116) : error C2065: 'sha' : undeclared identifier

src/pylzma/pylzma.c(116) : warning C4133: 'function' : incompatible types - from 'int *' to 'CSha256 *'

error: Setup script exited with error: command '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\cl.exe"' failed with exit status 2

然后,Google搜索后,我认为它是关于编译器(c90 vs c99),有人建议将.c扩展名改为.cpp。所以我做了这个,并相应地改变了setup.py(主要是文件名)。

然后成功,它在CpuArch.c(pp)和另一个有语法错误的文件进行了一些调整之后编译。

的事情,现在是链接呛:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\dev\pylzma\build\temp.win-amd64-2.6\Release\src\pylzma /LIBPATH:C:\Python26\libs /LIBPATH:C:\Python26\PCbuild\amd64 user32.lib oleaut32.lib /EXPORT:initpylzma build\temp.win-amd64-2.6\Release\src/pylzma/pylzma.obj build\temp.win-amd64-2.6\Release\src/pylzma/pylzma_decompressobj.obj build\temp.win-amd64-2.6\Release\src/pylzma/pylzma_compressfile.obj build\temp.win-amd64-2.6\Release\src/pylzma/pylzma_decompress.obj build\temp.win-amd64-2.6\Release\src/pylzma/pylzma_compress.obj build\temp.win-amd64-2.6\Release\src/pylzma/pylzma_streams.obj build\temp.win-amd64-2.6\Release\src/pylzma/pylzma_aes.obj build\temp.win-amd64-2.6\Release\src/pylzma/pylzma_decompress_compat.obj build\temp.win-amd64-2.6\Release\src/pylzma/pylzma_decompressobj_compat.obj build\temp.win-amd64-2.6\Release\src\sdk\LzFind.obj build\temp.win-amd64-2.6\Release\src\sdk\LzmaDec.obj build\temp.win-amd64-2.6\Release\src\sdk\LzmaEnc.obj build\temp.win-amd64-2.6\Release\src\7zip\C\CpuArch.obj build\temp.win-amd64-2.6\Release\src\7zip\C\Aes.obj build\temp.win-amd64-2.6\Release\src\7zip\C\AesOpt.obj build\temp.win-amd64-2.6\Release\src\7zip\C\Sha256.obj build\temp.win-amd64-2.6\Release\src\compat\LzmaCompatDecode.obj build\temp.win-amd64-2.6\Release\src/sdk/LzFindMt.obj build\temp.win-amd64-2.6\Release\src/sdk/Threads.obj /OUT:build\lib.win-amd64-2.6\pylzma.pyd /IMPLIB:build\temp.win-amd64-2.6\Release\src/pylzma\pylzma.lib /MANIFESTFILE:build\temp.win-amd64-2.6\Release\src/pylzma\pylzma.pyd.manifest

pylzma.obj : warning LNK4197: export 'initpylzma' specified multiple times; using first specification Creating library build\temp.win-amd64-2.6\Release\src/pylzma\pylzma.lib and object build\temp.win-amd64-2.6\Release\src/pylzma\pylzma.exp

pylzma.obj : error LNK2001: unresolved external symbol "char const * const doc_decompress" ([email protected]@3QBDB)

pylzma.obj : error LNK2001: unresolved external symbol "struct _object * __cdecl pylzma_decompress(struct _object *,struct _object *)" ([email protected]@[email protected]@[email protected]@Z)

pylzma.obj : error LNK2001: unresolved external symbol "char const * const doc_compress" ([email protected]@3QBDB)

Aes.obj : error LNK2019: unresolved external symbol "void __cdecl AesCtr_Code_Intel(unsigned int *,unsigned char *,unsigned __int64)" ([email protected]@[email protected]) referenced in function AesGenTables

Aes.obj : error LNK2019: unresolved external symbol "void __cdecl AesCbc_Decode_Intel(unsigned int *,unsigned char *,unsigned __int64)" ([email protected]@[email protected]) referenced in function AesGenTables

Aes.obj : error LNK2019: unresolved external symbol "void __cdecl AesCbc_Encode_Intel(unsigned int *,unsigned char *,unsigned __int64)" ([email protected]@[email protected]) referenced in function AesGenTables

AesOpt.obj : error LNK2019: unresolved external symbol _mm_aesenclast_si128 referenced in function "void __cdecl AesCbc_Encode_Intel(union __m128i *,union __m128i *,unsigned __int64)" ([email protected]@[email protected]@[email protected])

AesOpt.obj : error LNK2019: unresolved external symbol _mm_aesenc_si128 referenced in function "void __cdecl AesCbc_Encode_Intel(union __m128i *,union __m128i *,unsigned __int64)" ([email protected]@YAXPEA[email protected]@[email protected])

AesOpt.obj : error LNK2019: unresolved external symbol _mm_aesdeclast_si128 referenced in function "void __cdecl AesCbc_Decode_Intel(union __m128i *,union __m128i *,unsigned __int64)" ([email protected]@[email protected]@[email protected])

AesOpt.obj : error LNK2019: unresolved external symbol _mm_aesdec_si128 referenced in function "void __cdecl AesCbc_Decode_Intel(union __m128i *,union __m128i *,unsigned __int64)" ([email protected]@[email protected]@[email protected]) build\lib.win-amd64-2.6\pylzma.pyd : fatal error LNK1120: 10 unresolved externals

error: command '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\link.exe"' failed with exit status 1120

现在我已经很难试图找出这些连接问题是什么,甚至与MSDN文档(约接头错误)。可能是由于我对C/C++缺乏知识。

所以基本上我的问题(S)是:

  • 有没有办法来解决这些问题的链接?
  • 我错了将这些文件从.c重命名为.cpp。如果是,是否可以使用msvc amd64编译器将其编译为.c文件?

编辑 也不多了答案,所以我想我会添加一些问题:

  • 什么是你的做法,当涉及到链接程序错误?

  • 是否有任何逻辑可以帮助我通过网络找到答案(加上MSDN linker errors)?

  • 由于我见过很多人为32位系统成功编译它,它有可能在64位编译好,但由于架构类型而无法连接?

我在寻找更多的提示可能比完全有效的答案。

非常感谢您的帮助(:

+0

你试过用minGW来构建它吗? – Velociraptors 2011-02-04 19:17:38

+0

如果您已将文件扩展名更改为.cpp,是否确保函数原型具有“extern”C“{...}”块,以避免名称被破坏? – 2011-02-07 00:25:17

回答

2

我已经安装了pylzma尝试了这一点我自己的Python 2.6它建立精细与MinGW的,但MSVC编译器扼流圈python2.4-2.7。让我们先来看看错误:有问题

src/pylzma/pylzma.c(102) : error C2275: 'CSha256' : illegal use of this type as an expression c:\users\xavier.lapointe\appdata\local\temp\easy_install-2mfkqu\pylzma-0.4.3\src\pylzma../7zip/C/Sha256.h(18) : see declaration of 'CSha256'

代码是:

} else { 
    Py_BEGIN_ALLOW_THREADS 
    Sha256_Init(&sha); 
    CSha256 sha; 
    long round; 
    int i; 
    long rounds = (long) 1 << cycles; 
    unsigned char temp[8] = { 0,0,0,0,0,0,0,0 }; 
    for (round = 0; round < rounds; round++) { 

这显然是无效的C,因为C它不允许代码后声明变量。当你将.c重命名为.cpp时,你避免了这个错误,因为C++允许这样做(而mingw显然支持这个)。但切换到C++导致名称修改和链接错误。要解决这些问题,您可以在所有代码周围放置extern "C" { ... }

这是更好地解决SRC/pylzma/pylzma.c htough和修复是微不足道的 - 移动Py_BEGIN_ALLOW_THREADS和Sha256_Init(& SHA);之后变量声明:

} else { 
    CSha256 sha; 
    long round; 
    int i; 
    long rounds = (long) 1 << cycles; 
    unsigned char temp[8] = { 0,0,0,0,0,0,0,0 }; 
    Py_BEGIN_ALLOW_THREADS 
    Sha256_Init(&sha); 
    for (round = 0; round < rounds; round++) { 

现在pylzma编译罚款,但无法连接后,运行清单工具:

Creating library build\temp.win-amd64-2.6\Release\src/pylzma\pylzma.lib and o bject build\temp.win-amd64-2.6\Release\src/pylzma\pylzma.exp C:\Program Files\Microsoft SDKs\Windows\v7.0\bin\x64\mt.exe -nologo -manifest bu ild\temp.win-amd64-2.6\Release\src/pylzma\pylzma.pyd.manifest -outputresource:bu ild\lib.win-amd64-2.6\pylzma.pyd;2

build\temp.win-amd64-2.6\Release\src/pylzma\pylzma.pyd.manifest : general error c1010070: Failed to load and parse the manifest. The system cannot find the file specified. error: command 'mt.exe' failed with exit status 31

展望build目录显示,没有pylzma.pyd.manifest那里虽然它从可见输出link.exe具有/ MANIFEST:...开关。快速谷歌搜索“链接没有创建清单”发现http://bugs.python.org/issue4431它解释说,当使用/ MT交换清单不会创建,并且解决方案是将/ MANIFEST添加到链接器标志。好吧,让我们编辑pylzma的setup.py以添加链接标志MSVC编译:

if isinstance(self.compiler, MSVCCompiler): 
     # set flags only available when using MSVC 
     ext.extra_link_args.append('/MANIFEST') # force linker to create manifest 
     if COMPILE_DEBUG: 
      ext.extra_compile_args.append('/Zi') 
      ext.extra_compile_args.append('/MTd') 
      ext.extra_link_args.append('/DEBUG') 
     else: 
      ext.extra_compile_args.append('/MT') 

瞧,pylzma与MSVC精细现在的基础之上。我已经测试建筑蟒蛇2.4-2.7 32位和2.6-2.7 64位:

08.02.2011 10:08   71 844 pylzma-0.4.3dev-py2.4-win32.egg 
08.02.2011 10:09   71 480 pylzma-0.4.3dev-py2.5-win32.egg 
08.02.2011 10:07   79 358 pylzma-0.4.3dev-py2.6-win-amd64.egg 
08.02.2011 10:09   75 637 pylzma-0.4.3dev-py2.6-win32.egg 
08.02.2011 10:08   79 259 pylzma-0.4.3dev-py2.7-win-amd64.egg 
08.02.2011 10:09   75 540 pylzma-0.4.3dev-py2.7-win32.egg 
       6 File(s)  453 118 bytes 

至于一般方法的任何错误的 - 它可能需要一些知识和经验,了解什么是他们身后。