安装/编译 pylzma(lzma python 绑定)
我已经在作者 网站上发布了这个问题,但我想我也可以在这里问。
我一直在尝试使用以下设置安装 pylzma:
- Windows 7 x64
- Python 2.6.6 x64
- 来自 Windows Server 2003 sdk 的 amd64 编译器
- 克隆了 git repo git://github.com/fancycode/pylzma.git
使用简单的 <代码>easy_install pylzma 我得到了这个:
cl:命令行警告 D9025: 用“/MT”覆盖“/MD” pylzma.c src/pylzma/pylzma.c(85) :警告 C4244: '=' : 转换自 'Py_ssize_t' 到 'int',可能丢失 数据量
src/pylzma/pylzma.c(102):错误 C2275:'CSha256':非法使用此 键入表达式 c:\users\xavier.lapointe\appdata\local\temp\easy_install-2mfkqu\pylzma-0.4.3\src\pylzma../7zip/C/Sha256.h(18) :参见“CSha256”的声明
src/pylzma/pylzma.c(102):错误 C2146: 语法错误: 缺少 ';' 在标识符“sha”之前
src/pylzma/pylzma.c(102):错误 C2065:“sha”:未声明的标识符
src/pylzma/pylzma.c(103):错误 C2065:“sha”:未声明的标识符
src/pylzma/pylzma.c(103):警告 C4133:“函数”:不兼容的类型
- 从“int *”到“CSha256 *”
src/pylzma/pylzma.c(104):错误 C2143: 语法错误: 缺少 ';' 在“输入”之前
src/pylzma/pylzma.c(105):错误 C2143: 语法错误: 缺少 ';' 在“输入”之前
src/pylzma/pylzma.c(106):错误 C2143: 语法错误: 缺少 ';' 在“输入”之前
src/pylzma/pylzma.c(107):错误 C2143: 语法错误: 缺少 ';' 在“输入”之前
src/pylzma/pylzma.c(108):错误 C2065:'round':未声明的标识符
src/pylzma/pylzma.c(108):错误 C2065:'round':未声明的标识符
src/pylzma/pylzma.c(108):错误 C2065:“回合”:未声明 标识符
src/pylzma/pylzma.c(108):错误 C2065:'round':未声明的标识符
src/pylzma/pylzma.c(109):错误 C2065:“sha”:未声明的标识符
src/pylzma/pylzma.c(109):警告 C4133:“函数”:不兼容的类型
- 从“int *”到“CSha256 *”
src/pylzma/pylzma.c(110):错误 C2065:“sha”:未声明的标识符
src/pylzma/pylzma.c(110):警告 C4133:“函数”:不兼容的类型
- 从“int *”到“CSha256 *”
src/pylzma/pylzma.c(111):错误 C2065:“sha”:未声明的标识符
src/pylzma/pylzma.c(111):警告 C4133:“函数”:不兼容的类型
- 从“int *”到“CSha256 *”
src/pylzma/pylzma.c(111):错误 C2065:'temp':未声明的标识符
src/pylzma/pylzma.c(112):错误 C2065:“i”:未声明的标识符
src/pylzma/pylzma.c(112):错误 C2065:“i”:未声明的标识符
src/pylzma/pylzma.c(112):错误 C2065:“i”:未声明的标识符
src/pylzma/pylzma.c(113):错误 C2065:“temp”:未声明的标识符
src/pylzma/pylzma.c(113):错误 C2065:“i”:未声明的标识符
src/pylzma/pylzma.c(113):错误 C2109: 下标需要数组或 指针类型
src/pylzma/pylzma.c(116):错误 C2065:“sha”:未声明的标识符
src/pylzma/pylzma.c(116):警告 C4133:“函数”:不兼容的类型
- 从“int *”到“CSha256 *”
错误:安装脚本退出并出现错误: 命令 '"C:\Program Files (x86)\微软 Visual Studio 9.0\VC\BIN\amd64\cl.exe"' 失败,退出状态 2
然后在谷歌搜索后,我认为这是关于编译器(c90 vs c99)的问题,有些人建议将 .c 扩展名更改为 .cpp。所以我这样做了并相应地更改了 setup.py (主要是文件名)。
错误的文件中进行一些调整后编译。
然后成功,在 CpuArch.c(pp) 和另一个有语法
C:\Program Files (x86)\Microsoft 视觉工作室 9.0\VC\BIN\amd64\link.exe /DLL /nologo /增量:否 /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 /导出: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 构建\temp.win-amd64-2.6\Release\src\sdk\LzmaDec.obj构建\temp.win-amd64-2.6\Release\src\sdk\LzmaEnc.obj构建\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:警告 LNK4197:导出 多次指定“initpylzma”; 使用第一个规范创建 图书馆 build\temp.win-amd64-2.6\Release\src/pylzma\pylzma.lib 和对象 build\temp.win-amd64-2.6\Release\src/pylzma\pylzma.exp
pylzma.obj:错误 LNK2001:未解决 外部符号“char const * const doc_解压缩” (?doc_decompress@@3QBDB)
pylzma.obj:错误 LNK2001:未解决 外部符号“struct _object * __cdecl pylzma_decompress(struct _object *,struct _object *)" (?pylzma_decompress@@YAPEAU_object@@PEAU1@0@Z)
pylzma.obj:错误 LNK2001:未解决 外部符号“char const * const doc_compress" (?doc_compress@@3QBDB)
Aes.obj:错误 LNK2019:未解决 外部符号“void __cdecl AesCtr_Code_Intel(无符号整数 *,无符号字符 *,无符号 __int64)" (?AesCtr_Code_Intel@@YAXPEAIPEAE_K@Z) 在函数 AesGenTables 中引用
Aes.obj:错误 LNK2019:未解决 外部符号“void __cdecl AesCbc_Decode_Intel(无符号整数 *,无符号字符 *,无符号 __int64)" (?AesCbc_Decode_Intel@@YAXPEAIPEAE_K@Z) 在函数 AesGenTables 中引用
Aes.obj:错误 LNK2019:未解决 外部符号“void __cdecl AesCbc_Encode_Intel(无符号整数 *,无符号字符 *,无符号 __int64)" (?AesCbc_Encode_Intel@@YAXPEAIPEAE_K@Z) 在函数 AesGenTables 中引用
AesOpt.obj:错误 LNK2019:未解决 外部符号_mm_aesenclast_si128 在函数“void __cdecl”中引用 AesCbc_Encode_Intel(联盟 __m128i *,union __m128i *,无符号 __int64)" (?AesCbc_Encode_Intel@@YAXPEAT__m128i@@0_K@Z)
AesOpt.obj:错误 LNK2019:未解决 外部符号_mm_aesenc_si128 在函数“void __cdecl”中引用 AesCbc_Encode_Intel(联盟 __m128i *,union __m128i *,无符号 __int64)" (?AesCbc_Encode_Intel@@YAXPEAT__m128i@@0_K@Z)
AesOpt.obj:错误 LNK2019:未解决 外部符号_mm_aesdeclast_si128 在函数“void __cdecl”中引用 AesCbc_Decode_Intel(联盟 __m128i *,union __m128i *,无符号 __int64)" (?AesCbc_Decode_Intel@@YAXPEAT__m128i@@0_K@Z)
AesOpt.obj:错误 LNK2019:未解决 外部符号_mm_aesdec_si128 在函数“void __cdecl”中引用 AesCbc_Decode_Intel(联盟 __m128i *,联合 __m128i *,无符号 __int64)" (?AesCbc_Decode_Intel@@YAXPEAT__m128i@@0_K@Z) build\lib.win-amd64-2.6\pylzma.pyd : 致命错误 LNK1120:10 未解决 外部
错误:命令“”C:\Program Files (x86)\微软 Visual Studio 9.0\VC\BIN\amd64\link.exe"' 失败,退出状态为 1120
现在,即使有 msdn 文档(关于链接器错误),我也很难找出这些链接器问题是什么。可能是由于我缺乏 C/C++ 知识。
所以基本上我的问题是:
- 有没有办法解决这些链接器问题?
- 我是否错误地将这些文件从 .c 重命名为 .cpp 如果是,是否可以编译它。作为 .c 与 msvc amd64 编译器
编辑 没有得到太多答案,所以我想我会添加一些问题:
当涉及到链接器错误时,你的方法是什么?
我是否可以遵循任何逻辑来帮助自己在网络上找到答案(结合此MSDN 链接器错误)?
既然我看到很多人在 32 位系统上编译成功,是否有可能它在 64 位系统中编译得很好,但由于架构类型而在链接时失败?
我更多地寻找可能有帮助的提示,而不是一个完整的工作答案。
I've already posted this question on the authors website, but I thought I might ask here as well.
I've been trying to install pylzma with this setup:
- Windows 7 x64
- Python 2.6.6 x64
- the amd64 compiler coming from windows server 2003 sdk
- cloned the git repo git://github.com/fancycode/pylzma.git
With a simple easy_install pylzma
I got this:
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 datasrc/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 identifiersrc/pylzma/pylzma.c(103) : error
C2065: 'sha' : undeclared identifiersrc/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 identifiersrc/pylzma/pylzma.c(108) : error
C2065: 'round' : undeclared identifiersrc/pylzma/pylzma.c(108) : error
C2065: 'rounds' : undeclared
identifiersrc/pylzma/pylzma.c(108) : error
C2065: 'round' : undeclared identifiersrc/pylzma/pylzma.c(109) : error
C2065: 'sha' : undeclared identifiersrc/pylzma/pylzma.c(109) : warning
C4133: 'function' : incompatible types
- from 'int *' to 'CSha256 *'
src/pylzma/pylzma.c(110) : error
C2065: 'sha' : undeclared identifiersrc/pylzma/pylzma.c(110) : warning
C4133: 'function' : incompatible types
- from 'int *' to 'CSha256 *'
src/pylzma/pylzma.c(111) : error
C2065: 'sha' : undeclared identifiersrc/pylzma/pylzma.c(111) : warning
C4133: 'function' : incompatible types
- from 'int *' to 'CSha256 *'
src/pylzma/pylzma.c(111) : error
C2065: 'temp' : undeclared identifiersrc/pylzma/pylzma.c(112) : error
C2065: 'i' : undeclared identifiersrc/pylzma/pylzma.c(112) : error
C2065: 'i' : undeclared identifiersrc/pylzma/pylzma.c(112) : error
C2065: 'i' : undeclared identifiersrc/pylzma/pylzma.c(113) : error
C2065: 'temp' : undeclared identifiersrc/pylzma/pylzma.c(113) : error
C2065: 'i' : undeclared identifiersrc/pylzma/pylzma.c(113) : error
C2109: subscript requires array or
pointer typesrc/pylzma/pylzma.c(116) : error
C2065: 'sha' : undeclared identifiersrc/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
Then after googling I figured it was about the compiler (c90 vs c99), some people suggested to change the .c extension to .cpp. So I did this and changed the setup.py accordingly (mostly files name).
Then success, it compiles after a few tweaks in CpuArch.c(pp) and another file which had syntax errors.
The thing is now the linker choke:
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.manifestpylzma.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.exppylzma.obj : error LNK2001: unresolved
external symbol "char const * const
doc_decompress"
(?doc_decompress@@3QBDB)pylzma.obj : error LNK2001: unresolved
external symbol "struct _object *
__cdecl pylzma_decompress(struct _object *,struct _object *)" (?pylzma_decompress@@YAPEAU_object@@PEAU1@0@Z)pylzma.obj : error LNK2001: unresolved
external symbol "char const * const
doc_compress" (?doc_compress@@3QBDB)Aes.obj : error LNK2019: unresolved
external symbol "void __cdecl
AesCtr_Code_Intel(unsigned int
*,unsigned char *,unsigned __int64)" (?AesCtr_Code_Intel@@YAXPEAIPEAE_K@Z)
referenced in function AesGenTablesAes.obj : error LNK2019: unresolved
external symbol "void __cdecl
AesCbc_Decode_Intel(unsigned int
*,unsigned char *,unsigned __int64)" (?AesCbc_Decode_Intel@@YAXPEAIPEAE_K@Z)
referenced in function AesGenTablesAes.obj : error LNK2019: unresolved
external symbol "void __cdecl
AesCbc_Encode_Intel(unsigned int
*,unsigned char *,unsigned __int64)" (?AesCbc_Encode_Intel@@YAXPEAIPEAE_K@Z)
referenced in function AesGenTablesAesOpt.obj : error LNK2019: unresolved
external symbol _mm_aesenclast_si128
referenced in function "void __cdecl
AesCbc_Encode_Intel(union __m128i
*,union __m128i *,unsigned __int64)" (?AesCbc_Encode_Intel@@YAXPEAT__m128i@@0_K@Z)AesOpt.obj : error LNK2019: unresolved
external symbol _mm_aesenc_si128
referenced in function "void __cdecl
AesCbc_Encode_Intel(union __m128i
*,union __m128i *,unsigned __int64)" (?AesCbc_Encode_Intel@@YAXPEAT__m128i@@0_K@Z)AesOpt.obj : error LNK2019: unresolved
external symbol _mm_aesdeclast_si128
referenced in function "void __cdecl
AesCbc_Decode_Intel(union __m128i
*,union __m128i *,unsigned __int64)" (?AesCbc_Decode_Intel@@YAXPEAT__m128i@@0_K@Z)AesOpt.obj : error LNK2019: unresolved
external symbol _mm_aesdec_si128
referenced in function "void __cdecl
AesCbc_Decode_Intel(union __m128i
*,union __m128i *,unsigned __int64)" (?AesCbc_Decode_Intel@@YAXPEAT__m128i@@0_K@Z)
build\lib.win-amd64-2.6\pylzma.pyd :
fatal error LNK1120: 10 unresolved
externalserror: command '"C:\Program Files
(x86)\Microsoft Visual Studio
9.0\VC\BIN\amd64\link.exe"' failed with exit status 1120
Now I've a hard time trying to figure out what these linker issues are, even with the msdn doc (about linkers error). Probably due to my lack of knowledge with C/C++.
So basically my question(s) are:
- Is there a way to fix these linker issues?
- Am I wrong to rename those files from .c to .cpp. If yes, is it possible to compile it as .c with the msvc amd64 compiler?
EDIT
Haven't got much answer, so I think I'll add some questions:
What's your approach when it comes to linker error?
Is there any logic I can follow to help myself find answers over the web (combined with this MSDN linker errors)?
Since I've seen many people compile it successfully for 32 bit system, is it possible that it compiles fine in 64bit, but fails when it comes to linking because of the architecture type?
I'm looking more for hints that might help than a fully working answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经安装了 pylzma 来亲自尝试一下。对于 python 2.6,它可以很好地使用 mingw 构建,但对于 python2.4-2.7,msvc 编译器会卡住。我们先看看错误:
代码 的声明问题是:
这显然是无效的 C,因为不允许在代码后声明变量。当您将 .c 重命名为 .cpp 时,您避免了此错误,因为 C++ 允许这样做(并且 mingw 显然支持 C)。但切换到 C++ 会导致名称修改和链接错误。要修复这些问题,您可以在所有代码周围放置
extern "C" { ... }
。最好修复 src/pylzma/pylzma.c htough 并且修复很简单 - 移动 Py_BEGIN_ALLOW_THREADS 和 Sha256_Init(&sha);变量声明后:
现在 pylzma 可以正常编译,但在链接后无法运行清单工具:
查看构建目录,发现那里没有 pylzma.pyd.manifest,尽管从输出中可以看出 link.exe 有 /MANIFEST:... 开关。快速谷歌搜索“链接没有创建清单”发现 http://bugs.python.org/issue4431其中解释说,当使用 /MT 时,不会创建开关清单,解决方案是将 /MANIFEST 添加到链接器标志。好吧,让我们编辑 pylzma 的 setup.py 来添加 MSVC 编译器的链接器标志:
瞧,pylzma 现在可以使用 MSVC 构建了。我已经测试了使用 python 2.4-2.7 32 位和 2.6-2.7 64 位进行构建:
对于任何错误的一般方法 - 它可能需要一些知识和经验来理解它们背后的内容。
I have installed pylzma to try this out myself. For python 2.6 it builds fine with mingw, but msvc compiler chokes for python2.4-2.7. Let's see errors first:
Code in question is:
which is clearly invalid C since it's not allowed to declare variables after code. When you renamed .c to .cpp you avoided this error since C++ allows for this (and mingw supports this for C apparently). But switching to C++ led to name mangling and linking errors. To fix those you could place
extern "C" { ... }
around all the code.It's better to fix src/pylzma/pylzma.c htough and the fix is trivial - move Py_BEGIN_ALLOW_THREADS and Sha256_Init(&sha); after variable declarations:
Now pylzma compiles fine but fails to run manifest tool after linking:
Looking in build directory reveals that there is no pylzma.pyd.manifest there though it's seen from output that link.exe has /MANIFEST:... switch. Quick googling for "link didn't create manifest" finds http://bugs.python.org/issue4431 where it's explained that when using /MT switch manifest doesn't get created and the solution is to add /MANIFEST to linker flags. Alright, let's edit pylzma's setup.py to add that linker flag for MSVC compiler:
Voila, pylzma builds with MSVC fine now. I have tested building with python 2.4-2.7 32-bit and 2.6-2.7 64-bit:
As of general approach to any errors - it probably requires some knowledge and experience to understand what's behind them.