[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

时间:2021-04-29 05:42:26

1.7-ZIP简介

7-zip 是一款免费的压缩解压软件。ZIP格式的文件默认被苹果和微软支持,完全不需要额外安装其他软件就可以解压。但对于非US-ASCII编码的文件名和大于2GB的ZIP文件,可能需要借助如WinRAR和7-ZIP软件也解压。同时7-ZIP完全免费,其支持的7Z压缩格式的压缩率相对RAR压缩格式更好。7-ZIP官网是http://www.7-zip.org/

2.在VS2015上编译7-ZIP代码的详细步骤

需要的材料:

  1. Microsoft Visual Studio 2015
  2. 可以解压.bz2(如bunzip2.exe)和.tar文件格式的解压工具,如WinRAR(用于解压7-ZIP 9.20 版本源码)

步骤A:下载并解压源码文件

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

网站上有1)"LZMA SDK"和2)"7-Zip"两个项目,我们需要下载"7-Zip",并保存到你本地电脑。

用WinRAR解压源码。

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

对于9.20版本的源码可以用下面的命令行解压(需要安装bunzip和tar解压工具):

bunzip2.exe –d 7z920.tar.bz2

tar -xvf 7z920.tar

cd CPP

(剩下的命令需要在解压出来的CPP文件夹下完成)

步骤B:添加Visual Studio环境到系统Path

主要是添加"ml.exe" 和 "nmake"到系统环境。

默认的VS2015并没有添加上述两个程序到环境变量里,我们需要运行"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\vsvars32.bat"进行添加。上述的路径可能会因为您安装VS2015路径的不同而不同。

步骤C:修正7-ZIP源码

删除"源码\CPP\Build.mak"33行中的"-OPT:NOWIN98",(先解除只读属性)

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

在命令行中删除33行"-OPT:NOWIN98"的命令如下(需要vim编辑器):

vi .\CPP\Build.mak

OLD_BAD_LINE-> LFLAGS = $(LFLAGS) -OPT:NOWIN98

NEW_CORRECT-> LFLAGS = $(LFLAGS)

步骤D:编译它,生成exe(只支持xp及其更高级的系统)

用vs命令提示符工具nmake,cd到%7z_source%\CPP\7zip目录,执行

nmake NEW_COMPILER= MY_STATIC_LINK=

等待编译结束即可,编译大概需要几分钟的,看人品和机器配置。

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

步骤E:拷贝出生成的exe

上面的编译会产生如下的exe

.\CPP\7zip\Bundles\Alone\O\7za.exe        *******************支持ZIP文件

.\CPP\7zip\Bundles\Alone7z\O\7zr.exe    *******************

.\CPP\7zip\Bundles\Fm\O\7FM.exe        *******************文件管理'File Manager',图形界面gui

.\CPP\7zip\Bundles\LzmaCon\O\lmza.exe    *******************

.\CPP\7zip\UI\Client7z\O\7z.exe            *******************第一次运行会报错,无法加载7-zip库"Can not load 7-zip library"

.\CPP\7zip\UI\Console\O\7z.exe            *******************第一次运行报错,找不到压缩编码"7-Zip cannot find the code that works with archives."

.\CPP\7zip\UI\FileManager\O\7zFM.exe    *******************调频"Frequency Modulation"

.\CPP\7zip\UI\GUI\O\7z.exe                *******************

.\CPP\7zip\UI\Console\O\7z.exe            *******************这个可以直接用命令行模式使用

使用7za.exe,

copy .\CPP\7zip\Bundles\Alone\O\7za.exe D:\7-Zip\7za.exe ::先单独拷贝出exe程序

cd D:\tmp ::进入其他目录(这个目录下放一个foo.zip文件)

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

D:\7-Zip\7za.exe l D:\tmp\foo.zip ::列出foo.zip中的文件。

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

D:\7-Zip\7za.exe x D:\tmp\foo.zip ::解压foo.zip文件到当前文件夹

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

步骤F:用VS打开项目

使用VS打开%7z_source%\CPP\7zip\Bundles\Format7zF\Format7z.dsw,提示迁移有个错误。忽略即可。

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

打开后,第一次全部编译会报错

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

右键项目属性-》

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

C/C++ -》常规 –》调试信息格式 由"用于"编辑并继续"的程序数据库 (/ZI)"改为"程序数据库 (/Zi)"

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

C/C++ -》代码生成 –》启用函数级链接 –》改为"是 (/Gy)"

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

再次编译,报错信息如下(Debug模式下):

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

原因是由于C盘的特殊权限造成的。

把输出路径改一下:项目右键-》属性-》配置属性-》链接器-》常规-》输出文件 改为 比如说"D:\7-Zip\7z.dll"

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

更改后,请注意 项目右键-》属性-》配置属性-》链接器-》所有选项-》输入文件 也会自动变为更改后的路径。

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

再次编译,报错信息如下(Debug模式下):

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

原因是在Debug模式下7zCrcOpt.asm和AesOpt.asm的 属性-》配置属性-》自定义生成工具-》常规-》输出是

"$(OutDir)\$(InputName).obj;%(Outputs)",应改为"$(OutDir)\%(Filename).obj;%(Outputs)"

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

右键将两个asm文件的 属性-》配置属性-》自定义生成工具-》常规-》输出更改后,再次编译(Debug模式下),报错如下:

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

原因是7zCrcOpt.asm在Debug模式下 属性-》配置属性-》自定义生成工具-》常规-》命令行是

"ml.exe -c -omf -Fo$(OutDir)%(Filename).obj %(FullPath)"而Release模式下是"ml.exe -c -Fo$(OutDir)%(Filename).obj %(FullPath)"。-omf 意思是"generate OMF format object file".谁知道这是什么鬼。。删掉。

同时也把AesOpt.asm 属性-》配置属性-》自定义生成工具-》常规-》命令行改为

"ml.exe -c -Fo$(OutDir)%(Filename).obj %(FullPath)"

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

再次编译,报错信息如下:

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

解决办法:

项目属性 –》配置属性-》链接器-》命令行-》其他选项(D)中粘贴"/SAFESEH:NO"

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

终于编译通过了

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

同样的,如果要修改Release版本,也需要将7zCrcOpt.asm和AesOpt.asm做个修改。

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

附注,7-ZIP目录结构:

[Bundle]
Alone 7za.exe: Standalone version of 7z
Alone7z 7zr.exe: Standalone version of 7z that supports only 7z/LZMA/BCJ/BCJ2
SFXCon 7zCon.sfx: Console 7z SFX module
SFXWin 7z.sfx: Windows 7z SFX module
SFXSetup 7zS.sfx: Windows 7z SFX module for Installers
Format7z 7za.dll: .7z support
Format7zExtract 7zxa.dll: .7z support, extracting only
Format7zR 7zr.dll: .7z support, LZMA/BCJ* only
Format7zExtractR 7zxr.dll: .7z support, LZMA/BCJ* only, extracting only
Format7zF 7z.dll: all formats [UI]
Agent Intermediary modules for FAR plugin and Explorer plugin
Console 7z.exe Console version
Explorer Explorer plugin
Resource Resources
Far FAR plugin
Client7z Test application for 7za.dll [Compress]
BZip2 BZip2 compressor
Branch Branch converter
ByteSwap Byte Swap converter
Copy Copy coder
Deflate
Implode
Arj
LZMA
PPMd Dmitry Shkarin's PPMdH with small changes.
LZ Lempel - Ziv [Crypto]
7zAES Cipher for 7z
AES AES Cipher
Rar20 Cipher for Rar 2.0
RarAES Cipher for Rar 3.0
Zip Cipher for Zip