当前位置: 首页 > 工具软件 > 7-Zip > 使用案例 >

windows和linux下源码编译7-Zip(7za)

欧阳俊晖
2023-12-01

windows和linux下源码编译7-Zip(7za)


如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033

环境:

OS: windows 10
编译器:Visual Studio 2017
OS: Ubuntu 20.04
编译器:g++ 9.4.0

前言

7-Zip 是一款拥有极高压缩比的开源压缩软件。支持windows、linux、macOS。

7-Zip版本: 21.07(2021-12-26)

源码地址:https://www.7-zip.org/a/7z2107-src.tar.xz

1. windows下源码编译7-Zip

1.1 windows编译7za.exe

打开vs2017 64位命令行,进入目录

call "D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat" x64

cd 7z2107-src\CPP\7zip\Bundles\Alone
  • 静态编译7za.exe
nmake NEW_COMPILER=1 MY_STATIC_LINK=1
  • 动态编译7za.exe
nmake NEW_COMPILER=1 MY_STATIC_LINK=0 

1.2 windows编译7z.dll

打开vs2017 64位命令行行,进入目录

call "D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat" x64

cd 7z2107-src\CPP\7zip\Bundles\Format7zF
  • 静态编译(静态链接msvcrt.dll)【推荐】
nmake NEW_COMPILER=1 MY_STATIC_LINK=1
  • 动态编译(动态链接msvcrt.dll)
nmake NEW_COMPILER=1 MY_STATIC_LINK=0 

2. linux下源码编译7-Zip

2.1 linux编译7za

进入目录

mkdir 7z2107-src
tar xvJf 7z2107-src.tar.xz -C 7z2107-src

cd 7z2107-src\CPP\7zip\Bundles\Alone
  • 静态编译7za(静态链接-static)【推荐】
    修改7z2107-src/CPP/7zip/7zip_gcc.mak文件的第45行的LDFLAGS_STATIC_2,由空赋值为-static
LDFLAGS_STATIC_2 = -static
# -static
# -static-libstdc++ -static-libgcc

静态编译

$ make -f makefile.gcc

$ file 7za
7za: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=22269394e402fbccfb35017d21b3ffb9eb4994bf, for GNU/Linux 3.2.0, stripped
  • 动态编译7za
$ make -f makefile.gcc

$ file 7za
7za: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=5e07e05837089b8efb2627ff9d67be881dda4c19, for GNU/Linux 3.2.0, stripped

$ ldd 7za
linux-vdso.so.1 (0x00007ffd17262000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5d5404b000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5d53e69000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5d53e4e000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5d53c5c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f5d5421c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5d53b0d000)

2.2 linux编译7z.so

进入目录

cd 7z2107-src\CPP\7zip\Bundles\Format7zF

动态编译7z.so

$ make -f makefile.gcc

$ file 7z.so
7z.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=5c66ae8bb982aae3c8c37f0eba0c91a30fe152ec, stripped
$ ldd 7z.so
linux-vdso.so.1 (0x00007fff24d4c000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9ec200f000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f9ec1e2d000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f9ec1e12000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9ec1c20000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9ec22f2000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9ec1ad1000)

3.常用命令

7za详细命令

$ 7za -h

7-Zip (a) 21.07 (x64) : Copyright (c) 1999-2021 Igor Pavlov : 2021-12-26

Usage: 7za <command> [<switches>...] <archive_name> [<file_names>...] [@listfile]

<Commands>
  a : Add files to archive
  b : Benchmark
  d : Delete files from archive
  e : Extract files from archive (without using directory names)
  h : Calculate hash values for files
  i : Show information about supported formats
  l : List contents of archive
  rn : Rename files in archive
  t : Test integrity of archive
  u : Update files to archive
  x : eXtract files with full paths

<Switches>
  -- : Stop switches and @listfile parsing
  -ai[r[-|0]]{@listfile|!wildcard} : Include archives
  -ax[r[-|0]]{@listfile|!wildcard} : eXclude archives
  -ao{a|s|t|u} : set Overwrite mode
  -an : disable archive_name field
  -bb[0-3] : set output log level
  -bd : disable progress indicator
  -bs{o|e|p}{0|1|2} : set output stream for output/error/progress line
  -bt : show execution time statistics
  -i[r[-|0]]{@listfile|!wildcard} : Include filenames
  -m{Parameters} : set compression Method
    -mmt[N] : set number of CPU threads
    -mx[N] : set compression level: -mx1 (fastest) ... -mx9 (ultra)
  -o{Directory} : set Output directory
  -p{Password} : set Password
  -r[-|0] : Recurse subdirectories for name search
  -sa{a|e|s} : set Archive name mode
  -scc{UTF-8|WIN|DOS} : set charset for for console input/output
  -scs{UTF-8|UTF-16LE|UTF-16BE|WIN|DOS|{id}} : set charset for list files
  -scrc[CRC32|CRC64|SHA1|SHA256|*] : set hash function for x, e, h commands
  -sdel : delete files after compression
  -seml[.] : send archive by email
  -sfx[{name}] : Create SFX archive
  -si[{name}] : read data from stdin
  -slp : set Large Pages mode
  -slt : show technical information for l (List) command
  -snh : store hard links as links
  -snl : store symbolic links as links
  -sni : store NT security information
  -sns[-] : store NTFS alternate streams
  -so : write data to stdout
  -spd : disable wildcard matching for file names
  -spe : eliminate duplication of root folder for extract command
  -spf : use fully qualified file paths
  -ssc[-] : set sensitive case mode
  -sse : stop archive creating, if it can't open some input file
  -ssp : do not change Last Access Time of source files while archiving
  -ssw : compress shared files
  -stl : set archive timestamp from the most recently modified file
  -stm{HexMask} : set CPU thread affinity mask (hexadecimal number)
  -stx{Type} : exclude archive type
  -t{Type} : Set type of archive
  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName] : Update options
  -v{Size}[b|k|m|g] : Create volumes
  -w[{path}] : assign Work directory. Empty path means a temporary directory
  -x[r[-|0]]{@listfile|!wildcard} : eXclude filenames
  -y : assume Yes on all queries

4.其他

7z2107-src\DOC\readme.txt

    Alone         7za.exe: Standalone version of 7-Zip console that supports only 7z/xz/cab/zip/gzip/bzip2/tar.
    Alone2        7zz.exe: Standalone version of 7-Zip console that supports all formats.
    Alone7z       7zr.exe: Standalone version of 7-Zip console that supports only 7z (reduced version)
    Fm            Standalone version of 7-Zip File Manager
    Format7z            7za.dll:  .7z support
    Format7zExtract     7zxa.dll: .7z support, extracting only
    Format7zR           7zr.dll:  .7z support, reduced version
    Format7zExtractR    7zxr.dll: .7z support, reduced version, extracting only
    Format7zF           7z.dll:   all formats
    LzmaCon       lzma.exe: LZMA compression/decompression
    SFXCon        7zCon.sfx: Console 7z SFX module
    SFXWin        7z.sfx: Windows 7z SFX module
    SFXSetup      7zS.sfx: Windows 7z SFX module for Installers

License

License under CC BY-NC-ND 4.0: 署名-非商业使用-禁止演绎

如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033


Reference:
NULL

 类似资料: