2
2
================================
4
4
The `/lib` directory contains many files, but depending on project's objectives,
5
not all of them are necessary.
5
not all of them are required.
6
Limited systems may want to reduce the nb of source files to include
7
as a way to reduce binary size and dependencies.
9
Capabilities are added at the "level" granularity, detailed below.
11
#### Level 1 : Minimal LZ4 build
9
13
The minimum required is **`lz4.c`** and **`lz4.h`**,
10
14
which provides the fast compression and decompression algorithms.
11
15
They generate and decode data using the [LZ4 block format].
14
#### High Compression variant
18
#### Level 2 : High Compression variant
16
20
For more compression ratio at the cost of compression speed,
17
21
the High Compression variant called **lz4hc** is available.
20
24
and depends on regular `lib/lz4.*` source files.
23
#### Frame support, for interoperability
27
#### Level 3 : Frame support, for interoperability
25
29
In order to produce compressed data compatible with `lz4` command line utility,
26
30
it's necessary to use the [official interoperable frame format].
28
32
Its public API is described in `lib/lz4frame.h`.
29
33
In order to work properly, lz4frame needs all other modules present in `/lib`,
30
34
including, lz4 and lz4hc, and also **xxhash**.
31
So it's necessary to include all `*.c` and `*.h` files present in `/lib`.
35
So it's necessary to also include `xxhash.c` and `xxhash.h`.
38
#### Level 4 : File compression operations
40
As a helper around file operations,
41
the library has been recently extended with `lz4file.c` and `lz4file.h`
42
(still considered experimental at the time of this writing).
43
These helpers allow opening, reading, writing, and closing files
44
using transparent LZ4 compression / decompression.
45
As a consequence, using `lz4file` adds a dependency on `<stdio.h>`.
47
`lz4file` relies on `lz4frame` in order to produce compressed data
48
conformant to the [LZ4 Frame format] specification.
49
Consequently, to enable this capability,
50
it's necessary to include all `*.c` and `*.h` files from `lib/` directory.
34
53
#### Advanced / Experimental API
36
55
Definitions which are not guaranteed to remain stable in future versions,
37
56
are protected behind macros, such as `LZ4_STATIC_LINKING_ONLY`.
38
As the name strongly implies, these definitions should only be invoked
57
As the name suggests, these definitions should only be invoked
39
58
in the context of static linking ***only***.
40
59
Otherwise, dependent application may fail on API or ABI break in the future.
41
60
The associated symbols are also not exposed by the dynamic library by default.
58
77
Set to 65535 by default, which is the maximum value supported by lz4 format.
59
78
Reducing maximum distance will reduce opportunities for LZ4 to find matches,
60
79
hence will produce a worse compression ratio.
61
However, a smaller max distance can allow compatibility with specific decoders using limited memory budget.
80
Setting a smaller max distance could allow compatibility with specific decoders with limited memory budget.
62
81
This build macro only influences the compressed output of the compressor.
64
83
- `LZ4_DISABLE_DEPRECATE_WARNINGS` : invoking a deprecated function will make the compiler generate a warning.
69
88
This build macro offers another project-specific method
70
89
by defining `LZ4_DISABLE_DEPRECATE_WARNINGS` before including the LZ4 header files.
72
- `LZ4_USER_MEMORY_FUNCTIONS` : replace calls to <stdlib>'s `malloc`, `calloc` and `free`
73
by user-defined functions, which must be called `LZ4_malloc()`, `LZ4_calloc()` and `LZ4_free()`.
74
User functions must be available at link time.
76
91
- `LZ4_FORCE_SW_BITCOUNT` : by default, the compression algorithm tries to determine lengths
77
92
by using bitcount instructions, generally implemented as fast single instructions in many cpus.
78
93
In case the target cpus doesn't support it, or compiler intrinsic doesn't work, or feature bad performance,
79
94
it's possible to use an optimized software path instead.
80
This is achieved by setting this build macros .
95
This is achieved by setting this build macros.
81
96
In most cases, it's not expected to be necessary,
82
97
but it can be legitimately considered for less common platforms.
85
100
passed as argument to become a compression state is suitably aligned.
86
101
This test can be disabled if it proves flaky, by setting this value to 0.
103
- `LZ4_USER_MEMORY_FUNCTIONS` : replace calls to `<stdlib,h>`'s `malloc()`, `calloc()` and `free()`
104
by user-defined functions, which must be named `LZ4_malloc()`, `LZ4_calloc()` and `LZ4_free()`.
105
User functions must be available at link time.
107
- `LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION` :
108
Remove support of dynamic memory allocation.
109
For more details, see description of this macro in `lib/lz4.c`.
111
- `LZ4_FREESTANDING` : by setting this build macro to 1,
112
LZ4/HC removes dependencies on the C standard library,
113
including allocation functions and `memmove()`, `memcpy()`, and `memset()`.
114
This build macro is designed to help use LZ4/HC in restricted environments
115
(embedded, bootloader, etc).
116
For more details, see description of this macro in `lib/lz4.h`.
102
133
DLL can be created using MinGW+MSYS with the `make liblz4` command.
103
134
This command creates `dll\liblz4.dll` and the import library `dll\liblz4.lib`.
104
To override the `dlltool` command when cross-compiling on Linux, just set the `DLLTOOL` variable. Example of cross compilation on Linux with mingw-w64 64 bits:
135
To override the `dlltool` command when cross-compiling on Linux, just set the `DLLTOOL` variable. Example of cross compilation on Linux with mingw-w64 64 bits:
106
137
make BUILD_STATIC=no CC=x86_64-w64-mingw32-gcc DLLTOOL=x86_64-w64-mingw32-dlltool OS=Windows_NT