QT编译liblzma

liblzma库是xz utils的子集,这里先下载xz utils源码

新建xz_lib文件夹。解压xz utils源码,取出extra,lib,src三个文件夹,并放入xz_lib文件夹中。

再将config.h.in重命名为config.h,放入xz_lib文件夹中,并修改成下面这样:


#ifndef CONFIG_H
#define CONFIG_H

/* Prefix for symbols exported by tuklib_*.c files */
#define TUKLIB_SYMBOL_PREFIX lzma_

/* How many MiB of RAM to assume if the real amount cannot be determined. */
#define ASSUME_RAM 128

/* Define to 1 if crc32 integrity check is enabled. */
#define HAVE_CHECK_CRC32 1

/* Define to 1 if crc64 integrity check is enabled. */
//#define HAVE_CHECK_CRC64 0
#undef HAVE_CHECK_CRC64

/* Define to 1 if sha256 integrity check is enabled. */
#define HAVE_CHECK_SHA256 1

/* Define to 1 if any of HAVE_DECODER_foo have been defined. */
#define HAVE_DECODERS 1

/* Define to 1 if arm decoder is enabled. */
#undef HAVE_DECODER_ARM

/* Define to 1 if armthumb decoder is enabled. */
#undef HAVE_DECODER_ARMTHUMB

/* Define to 1 if delta decoder is enabled. */
#define HAVE_DECODER_DELTA 1

/* Define to 1 if ia64 decoder is enabled. */
#undef HAVE_DECODER_IA64

/* Define to 1 if lzma1 decoder is enabled. */
#define HAVE_DECODER_LZMA1 1

/* Define to 1 if lzma2 decoder is enabled. */
#define HAVE_DECODER_LZMA2 1

/* Define to 1 if powerpc decoder is enabled. */
#undef HAVE_DECODER_POWERPC

/* Define to 1 if sparc decoder is enabled. */
#undef HAVE_DECODER_SPARC

/* Define to 1 if x86 decoder is enabled. */
#define HAVE_DECODER_X86 1

/* Define to 1 if any of HAVE_ENCODER_foo have been defined. */
#define HAVE_ENCODERS 1

/* Define to 1 if arm encoder is enabled. */
#undef HAVE_ENCODER_ARM

/* Define to 1 if armthumb encoder is enabled. */
#undef HAVE_ENCODER_ARMTHUMB

/* Define to 1 if delta encoder is enabled. */
#define HAVE_ENCODER_DELTA 1

/* Define to 1 if ia64 encoder is enabled. */
#undef HAVE_ENCODER_IA64

/* Define to 1 if lzma1 encoder is enabled. */
#define HAVE_ENCODER_LZMA1 1

/* Define to 1 if lzma2 encoder is enabled. */
#define HAVE_ENCODER_LZMA2 1

/* Define to 1 if powerpc encoder is enabled. */
#undef HAVE_ENCODER_POWERPC

/* Define to 1 if sparc encoder is enabled. */
#undef HAVE_ENCODER_SPARC

/* Define to 1 if x86 encoder is enabled. */
#define HAVE_ENCODER_X86 1

/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1

/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1

/* Define to 1 to enable bt2 match finder. */
#define HAVE_MF_BT2 1

/* Define to 1 to enable bt3 match finder. */
#define HAVE_MF_BT3 1

/* Define to 1 to enable bt4 match finder. */
#define HAVE_MF_BT4 1

/* Define to 1 to enable hc3 match finder. */
#define HAVE_MF_HC3 1

/* Define to 1 to enable hc4 match finder. */
#define HAVE_MF_HC4 1

/* Define to 1 if stdbool.h conforms to C99. */
#define HAVE_STDBOOL_H 1

/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1

/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1

/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1

/* Define to 1 or 0, depending whether the compiler supports simple visibility
   declarations. */
#define HAVE_VISIBILITY 0

/* Define to 1 if the system has the type `_Bool'. */
#define HAVE__BOOL 1

#ifdef _M_IX86
/* Define to 1 when using Windows 95 (and thus XP) compatible threads. This
   avoids use of features that were added in Windows Vista.
   This is used for 32-bit x86 builds for compatibility reasons since it
   makes no measurable difference in performance compared to Vista threads. */
#define MYTHREAD_WIN95 1
#else
/* Define to 1 when using Windows Vista compatible threads. This uses features
   that are not available on Windows XP. */
#define MYTHREAD_VISTA 1
#endif

/* Define to 1 to disable debugging code. */
#define NDEBUG 1

/* Define to the full name of this package. */
#define PACKAGE_NAME "XZ Utils"

/* Define to the home page for this package. */
#define PACKAGE_URL "https://tukaani.org/xz/"

#define PACKAGE_BUGREPORT "https://tukaani.org/xz/"

/* The size of `size_t', as computed by sizeof. */
#ifdef _WIN64
#define SIZEOF_SIZE_T 8
#else
#define SIZEOF_SIZE_T 4
#endif

/* Define to 1 if the number of available CPU cores can be detected with
   cpuset(2). */
#undef TUKLIB_CPUCORES_CPUSET

/* Define to 1 if the number of available CPU cores can be detected with
   pstat_getdynamic(). */
#undef TUKLIB_CPUCORES_PSTAT_GETDYNAMIC

/* Define to 1 if the number of available CPU cores can be detected with
   sched_getaffinity() */
#undef TUKLIB_CPUCORES_SCHED_GETAFFINITY

/* Define to 1 if the number of available CPU cores can be detected with
   sysconf(_SC_NPROCESSORS_ONLN) or sysconf(_SC_NPROC_ONLN). */
#undef TUKLIB_CPUCORES_SYSCONF

/* Define to 1 if the number of available CPU cores can be detected with
   sysctl(). */
#undef TUKLIB_CPUCORES_SYSCTL

/* Define to 1 if the system supports fast unaligned access to 16-bit and
   32-bit integers. */
#undef TUKLIB_FAST_UNALIGNED_ACCESS

/* Define to 1 if the amount of physical memory can be detected with
   _system_configuration.physmem. */
#undef TUKLIB_PHYSMEM_AIX

/* Define to 1 if the amount of physical memory can be detected with
   getinvent_r(). */
#undef TUKLIB_PHYSMEM_GETINVENT_R

/* Define to 1 if the amount of physical memory can be detected with
   getsysinfo(). */
#undef TUKLIB_PHYSMEM_GETSYSINFO

/* Define to 1 if the amount of physical memory can be detected with
   pstat_getstatic(). */
#undef TUKLIB_PHYSMEM_PSTAT_GETSTATIC

/* Define to 1 if the amount of physical memory can be detected with
   sysconf(_SC_PAGESIZE) and sysconf(_SC_PHYS_PAGES). */
#undef TUKLIB_PHYSMEM_SYSCONF

/* Define to 1 if the amount of physical memory can be detected with sysctl().
   */
#undef TUKLIB_PHYSMEM_SYSCTL

/* Define to 1 if the amount of physical memory can be detected with Linux
   sysinfo(). */
#undef TUKLIB_PHYSMEM_SYSINFO

/* Define to 1 to use unsafe type punning, e.g. char *x = ...; *(int *)x =
   123; which violates strict aliasing rules and thus is undefined behavior
   and might result in broken code. */
#undef TUKLIB_USE_UNSAFE_TYPE_PUNNING

#endif

新建QT控制台工程,删除main.cpp,再将xz_lib文件夹放到工程目录中。

修改.pro为下面这样:

QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    xz_lib/extra/scanlzma/scanlzma.c \
    xz_lib/lib/getopt.c \
    xz_lib/lib/getopt1.c \
    xz_lib/src/common/tuklib_cpucores.c \
    xz_lib/src/common/tuklib_exit.c \
    xz_lib/src/common/tuklib_mbstr_fw.c \
    xz_lib/src/common/tuklib_mbstr_width.c \
    xz_lib/src/common/tuklib_open_stdxxx.c \
    xz_lib/src/common/tuklib_physmem.c \
    xz_lib/src/common/tuklib_progname.c \
    xz_lib/src/liblzma/check/check.c \
    xz_lib/src/liblzma/check/crc32_fast.c \
    xz_lib/src/liblzma/check/crc32_small.c \
    xz_lib/src/liblzma/check/crc32_table.c \
    xz_lib/src/liblzma/check/crc64_fast.c \
    xz_lib/src/liblzma/check/crc64_small.c \
    xz_lib/src/liblzma/check/crc64_table.c \
    xz_lib/src/liblzma/check/sha256.c \
    xz_lib/src/liblzma/common/alone_decoder.c \
    xz_lib/src/liblzma/common/alone_encoder.c \
    xz_lib/src/liblzma/common/auto_decoder.c \
    xz_lib/src/liblzma/common/block_buffer_decoder.c \
    xz_lib/src/liblzma/common/block_buffer_encoder.c \
    xz_lib/src/liblzma/common/block_decoder.c \
    xz_lib/src/liblzma/common/block_encoder.c \
    xz_lib/src/liblzma/common/block_header_decoder.c \
    xz_lib/src/liblzma/common/block_header_encoder.c \
    xz_lib/src/liblzma/common/block_util.c \
    xz_lib/src/liblzma/common/common.c \
    xz_lib/src/liblzma/common/easy_buffer_encoder.c \
    xz_lib/src/liblzma/common/easy_decoder_memusage.c \
    xz_lib/src/liblzma/common/easy_encoder.c \
    xz_lib/src/liblzma/common/easy_encoder_memusage.c \
    xz_lib/src/liblzma/common/easy_preset.c \
    xz_lib/src/liblzma/common/filter_buffer_decoder.c \
    xz_lib/src/liblzma/common/filter_buffer_encoder.c \
    xz_lib/src/liblzma/common/filter_common.c \
    xz_lib/src/liblzma/common/filter_decoder.c \
    xz_lib/src/liblzma/common/filter_encoder.c \
    xz_lib/src/liblzma/common/filter_flags_decoder.c \
    xz_lib/src/liblzma/common/filter_flags_encoder.c \
    xz_lib/src/liblzma/common/index.c \
    xz_lib/src/liblzma/common/index_decoder.c \
    xz_lib/src/liblzma/common/index_encoder.c \
    xz_lib/src/liblzma/common/index_hash.c \
    xz_lib/src/liblzma/common/outqueue.c \
    xz_lib/src/liblzma/common/stream_buffer_decoder.c \
    xz_lib/src/liblzma/common/stream_buffer_encoder.c \
    xz_lib/src/liblzma/common/stream_decoder.c \
    xz_lib/src/liblzma/common/stream_encoder.c \
    xz_lib/src/liblzma/common/stream_encoder_mt.c \
    xz_lib/src/liblzma/common/stream_flags_common.c \
    xz_lib/src/liblzma/common/stream_flags_decoder.c \
    xz_lib/src/liblzma/common/stream_flags_encoder.c \
    xz_lib/src/liblzma/common/vli_decoder.c \
    xz_lib/src/liblzma/common/vli_encoder.c \
    xz_lib/src/liblzma/common/vli_size.c \
    xz_lib/src/liblzma/delta/delta_common.c \
    xz_lib/src/liblzma/delta/delta_decoder.c \
    xz_lib/src/liblzma/delta/delta_encoder.c \
    xz_lib/src/liblzma/lz/lz_decoder.c \
    xz_lib/src/liblzma/lz/lz_encoder.c \
    xz_lib/src/liblzma/lz/lz_encoder_mf.c \
    xz_lib/src/liblzma/lzma/fastpos_table.c \
    xz_lib/src/liblzma/lzma/lzma2_decoder.c \
    xz_lib/src/liblzma/lzma/lzma2_encoder.c \
    xz_lib/src/liblzma/lzma/lzma_decoder.c \
    xz_lib/src/liblzma/lzma/lzma_encoder.c \
    xz_lib/src/liblzma/lzma/lzma_encoder_optimum_fast.c \
    xz_lib/src/liblzma/lzma/lzma_encoder_optimum_normal.c \
    xz_lib/src/liblzma/lzma/lzma_encoder_presets.c \
    xz_lib/src/liblzma/rangecoder/price_table.c \
    xz_lib/src/liblzma/simple/simple_coder.c \
    xz_lib/src/liblzma/simple/simple_decoder.c \
    xz_lib/src/liblzma/simple/simple_encoder.c \
    xz_lib/src/liblzma/simple/x86.c \

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

HEADERS += \
    xz_lib/config.h \
    xz_lib/lib/getopt.h \
    xz_lib/lib/getopt_int.h \
    xz_lib/src/common/mythread.h \
    xz_lib/src/common/sysdefs.h \
    xz_lib/src/common/tuklib_common.h \
    xz_lib/src/common/tuklib_config.h \
    xz_lib/src/common/tuklib_cpucores.h \
    xz_lib/src/common/tuklib_exit.h \
    xz_lib/src/common/tuklib_gettext.h \
    xz_lib/src/common/tuklib_integer.h \
    xz_lib/src/common/tuklib_mbstr.h \
    xz_lib/src/common/tuklib_open_stdxxx.h \
    xz_lib/src/common/tuklib_physmem.h \
    xz_lib/src/common/tuklib_progname.h \
    xz_lib/src/liblzma/api/lzma.h \
    xz_lib/src/liblzma/check/check.h \
    xz_lib/src/liblzma/check/crc32_table_be.h \
    xz_lib/src/liblzma/check/crc32_table_le.h \
    xz_lib/src/liblzma/check/crc64_table_be.h \
    xz_lib/src/liblzma/check/crc64_table_le.h \
    xz_lib/src/liblzma/check/crc_macros.h \
    xz_lib/src/liblzma/common/alone_decoder.h \
    xz_lib/src/liblzma/common/block_buffer_encoder.h \
    xz_lib/src/liblzma/common/block_decoder.h \
    xz_lib/src/liblzma/common/block_encoder.h \
    xz_lib/src/liblzma/common/common.h \
    xz_lib/src/liblzma/common/easy_preset.h \
    xz_lib/src/liblzma/common/filter_common.h \
    xz_lib/src/liblzma/common/filter_decoder.h \
    xz_lib/src/liblzma/common/filter_encoder.h \
    xz_lib/src/liblzma/common/index.h \
    xz_lib/src/liblzma/common/index_encoder.h \
    xz_lib/src/liblzma/common/memcmplen.h \
    xz_lib/src/liblzma/common/outqueue.h \
    xz_lib/src/liblzma/common/stream_decoder.h \
    xz_lib/src/liblzma/common/stream_flags_common.h \
    xz_lib/src/liblzma/delta/delta_common.h \
    xz_lib/src/liblzma/delta/delta_decoder.h \
    xz_lib/src/liblzma/delta/delta_encoder.h \
    xz_lib/src/liblzma/delta/delta_private.h \
    xz_lib/src/liblzma/lz/lz_decoder.h \
    xz_lib/src/liblzma/lz/lz_encoder.h \
    xz_lib/src/liblzma/lz/lz_encoder_hash.h \
    xz_lib/src/liblzma/lz/lz_encoder_hash_table.h \
    xz_lib/src/liblzma/lzma/fastpos.h \
    xz_lib/src/liblzma/lzma/lzma2_decoder.h \
    xz_lib/src/liblzma/lzma/lzma2_encoder.h \
    xz_lib/src/liblzma/lzma/lzma_common.h \
    xz_lib/src/liblzma/lzma/lzma_decoder.h \
    xz_lib/src/liblzma/lzma/lzma_encoder.h \
    xz_lib/src/liblzma/lzma/lzma_encoder_private.h \
    xz_lib/src/liblzma/rangecoder/price.h \
    xz_lib/src/liblzma/rangecoder/range_common.h \
    xz_lib/src/liblzma/rangecoder/range_decoder.h \
    xz_lib/src/liblzma/rangecoder/range_encoder.h \
    xz_lib/src/liblzma/simple/simple_coder.h \
    xz_lib/src/liblzma/simple/simple_decoder.h \
    xz_lib/src/liblzma/simple/simple_encoder.h \
    xz_lib/src/liblzma/simple/simple_private.h \

INCLUDEPATH += \
xz_lib \
xz_lib/lib \
xz_lib/src \
xz_lib/src/common \
xz_lib/src/liblzma \
xz_lib/src/liblzma/api \
xz_lib/src/liblzma/lzma \
xz_lib/src/liblzma/rangecoder \
xz_lib/src/liblzma/common \
xz_lib/src/liblzma/simple \
xz_lib/src/liblzma/lz \
xz_lib/src/liblzma/delta \
xz_lib/src/liblzma/check \

最终运行结果如下图所示:

其中main函数在extra\scanlzma文件夹中。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值