From 3d18088b386e349fd51ddd11b765efe7d85577e8 Mon Sep 17 00:00:00 2001 From: Przemyslaw Skibinski Date: Thu, 17 Nov 2016 18:04:41 +0100 Subject: [PATCH 01/10] updated windres --- lib/compress/zstd_compress.c | 4 ++-- programs/windres/zstd32.res | Bin 1044 -> 1044 bytes programs/windres/zstd64.res | Bin 1044 -> 1044 bytes 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index d152d10dc..f7286ae8f 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -739,8 +739,8 @@ MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const v { #if 0 /* for debug */ static const BYTE* g_start = NULL; - const U32 pos = (U32)(literals - g_start); - if (g_start==NULL) g_start = literals; + const U32 pos = (U32)((const BYTE*)literals - g_start); + if (g_start==NULL) g_start = (const BYTE*)literals; //if ((pos > 1) && (pos < 50000)) printf("Cpos %6u :%5u literals & match %3u bytes at distance %6u \n", pos, (U32)litLength, (U32)matchCode+MINMATCH, (U32)offsetCode); diff --git a/programs/windres/zstd32.res b/programs/windres/zstd32.res index aec8fcf24e4f15e1915af725ba5b957fa3e7b50a..6135dc431fed231ce2143b394625bc0b52b0615a 100644 GIT binary patch delta 33 pcmbQjF@ Date: Fri, 18 Nov 2016 11:46:30 +0100 Subject: [PATCH 02/10] bench.c without dict uses ZSTD_compressCCtx --- .gitignore | 2 ++ programs/bench.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 220a1e0eb..6f792e615 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ _zstdbench/ .DS_Store googletest/ *.d + +build/VS2010/zwrapbench/zwrapbench.vcxproj \ No newline at end of file diff --git a/programs/bench.c b/programs/bench.c index 7b6e25206..df68d0ada 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -213,11 +213,18 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, if (cdict==NULL) EXM_THROW(1, "ZSTD_createCDict_advanced() allocation failure"); do { U32 blockNb; + size_t rSize; for (blockNb=0; blockNb Date: Mon, 21 Nov 2016 12:33:10 +0100 Subject: [PATCH 03/10] VC projects: removed ZBUFF references --- build/.gitignore | 1 + build/VS2010/fullbench/fullbench.vcxproj | 3 --- build/VS2010/fuzzer/fuzzer.vcxproj | 1 - build/VS2010/libzstd-dll/libzstd-dll.vcxproj | 3 --- build/VS2010/libzstd/libzstd.vcxproj | 3 --- build/VS2010/zstd/zstd.vcxproj | 3 --- 6 files changed, 1 insertion(+), 13 deletions(-) diff --git a/build/.gitignore b/build/.gitignore index bc8ac94d9..51fed59bb 100644 --- a/build/.gitignore +++ b/build/.gitignore @@ -6,6 +6,7 @@ *.sdf *.suo *.user +*.opendb VS2005/ VS2008/ diff --git a/build/VS2010/fullbench/fullbench.vcxproj b/build/VS2010/fullbench/fullbench.vcxproj index 67fd62ba7..e16f5e1db 100644 --- a/build/VS2010/fullbench/fullbench.vcxproj +++ b/build/VS2010/fullbench/fullbench.vcxproj @@ -162,10 +162,8 @@ - - @@ -174,7 +172,6 @@ - diff --git a/build/VS2010/fuzzer/fuzzer.vcxproj b/build/VS2010/fuzzer/fuzzer.vcxproj index 82fc02167..7227c7ec0 100644 --- a/build/VS2010/fuzzer/fuzzer.vcxproj +++ b/build/VS2010/fuzzer/fuzzer.vcxproj @@ -174,7 +174,6 @@ - diff --git a/build/VS2010/libzstd-dll/libzstd-dll.vcxproj b/build/VS2010/libzstd-dll/libzstd-dll.vcxproj index 5b894b05b..81da84c7d 100644 --- a/build/VS2010/libzstd-dll/libzstd-dll.vcxproj +++ b/build/VS2010/libzstd-dll/libzstd-dll.vcxproj @@ -26,10 +26,8 @@ - - @@ -49,7 +47,6 @@ - diff --git a/build/VS2010/libzstd/libzstd.vcxproj b/build/VS2010/libzstd/libzstd.vcxproj index 18f9f643b..661c20dfc 100644 --- a/build/VS2010/libzstd/libzstd.vcxproj +++ b/build/VS2010/libzstd/libzstd.vcxproj @@ -26,10 +26,8 @@ - - @@ -49,7 +47,6 @@ - diff --git a/build/VS2010/zstd/zstd.vcxproj b/build/VS2010/zstd/zstd.vcxproj index c7a9ed73c..5b5852689 100644 --- a/build/VS2010/zstd/zstd.vcxproj +++ b/build/VS2010/zstd/zstd.vcxproj @@ -26,10 +26,8 @@ - - @@ -52,7 +50,6 @@ - From 93a09eedf1bb6c281f003aaae37cd2f0a1d3cf80 Mon Sep 17 00:00:00 2001 From: Przemyslaw Skibinski Date: Mon, 21 Nov 2016 12:33:27 +0100 Subject: [PATCH 04/10] added libzstd.def --- lib/dll/libzstd.def | 86 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 lib/dll/libzstd.def diff --git a/lib/dll/libzstd.def b/lib/dll/libzstd.def new file mode 100644 index 000000000..0a3259e9e --- /dev/null +++ b/lib/dll/libzstd.def @@ -0,0 +1,86 @@ +LIBRARY libzstd.dll +EXPORTS + ZDICT_getDictID + ZDICT_getErrorName + ZDICT_isError + ZDICT_trainFromBuffer + ZSTD_CStreamInSize + ZSTD_CStreamOutSize + ZSTD_DStreamInSize + ZSTD_DStreamOutSize + ZSTD_adjustCParams + ZSTD_checkCParams + ZSTD_compress + ZSTD_compressBegin + ZSTD_compressBegin_advanced + ZSTD_compressBegin_usingDict + ZSTD_compressBlock + ZSTD_compressBound + ZSTD_compressCCtx + ZSTD_compressContinue + ZSTD_compressEnd + ZSTD_compressStream + ZSTD_compress_advanced + ZSTD_compress_usingCDict + ZSTD_compress_usingDict + ZSTD_copyCCtx + ZSTD_copyDCtx + ZSTD_createCCtx + ZSTD_createCCtx_advanced + ZSTD_createCDict + ZSTD_createCDict_advanced + ZSTD_createCStream + ZSTD_createCStream_advanced + ZSTD_createDCtx + ZSTD_createDCtx_advanced + ZSTD_createDDict + ZSTD_createDStream + ZSTD_createDStream_advanced + ZSTD_decompress + ZSTD_decompressBegin + ZSTD_decompressBegin_usingDict + ZSTD_decompressBlock + ZSTD_decompressContinue + ZSTD_decompressDCtx + ZSTD_decompressStream + ZSTD_decompress_usingDDict + ZSTD_decompress_usingDict + ZSTD_endStream + ZSTD_estimateCCtxSize + ZSTD_estimateDCtxSize + ZSTD_flushStream + ZSTD_freeCCtx + ZSTD_freeCDict + ZSTD_freeCStream + ZSTD_freeDCtx + ZSTD_freeDDict + ZSTD_freeDStream + ZSTD_getBlockSizeMax + ZSTD_getCParams + ZSTD_getDecompressedSize + ZSTD_getErrorName + ZSTD_getFrameParams + ZSTD_getParams + ZSTD_initCStream + ZSTD_initCStream_advanced + ZSTD_initCStream_usingCDict + ZSTD_initCStream_usingDict + ZSTD_initDStream + ZSTD_initDStream_usingDDict + ZSTD_initDStream_usingDict + ZSTD_insertBlock + ZSTD_isError + ZSTD_isFrame + ZSTD_maxCLevel + ZSTD_nextInputType + ZSTD_nextSrcSizeToDecompress + ZSTD_resetCStream + ZSTD_resetDStream + ZSTD_setDStreamParameter + ZSTD_sizeof_CCtx + ZSTD_sizeof_CDict + ZSTD_sizeof_CStream + ZSTD_sizeof_DCtx + ZSTD_sizeof_DDict + ZSTD_sizeof_DStream + ZSTD_versionNumber From 8bb86e330b80bfb29fffc25fa38affdb2dfa44e9 Mon Sep 17 00:00:00 2001 From: Przemyslaw Skibinski Date: Mon, 21 Nov 2016 12:51:01 +0100 Subject: [PATCH 05/10] create DLL with Windows --- lib/Makefile | 9 ++++++--- tests/Makefile | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 3aacb831c..681c048c6 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -72,8 +72,11 @@ libzstd.a: $(ZSTD_FILES) $(LIBZSTD): LDFLAGS += -shared -fPIC $(LIBZSTD): $(ZSTD_FILES) @echo compiling dynamic library $(LIBVER) +ifneq (,$(filter Windows%,$(OS))) + @$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -shared $^ -o dll\libzstd.dll + dlltool -D dll\libzstd.dll -d dll\libzstd.def -l dll\libzstd.lib +else @$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@ -ifeq (,$(filter Windows%,$(OS))) @echo creating versioned links @ln -sf $@ libzstd.$(SHARED_EXT_MAJOR) @ln -sf $@ libzstd.$(SHARED_EXT) @@ -84,8 +87,8 @@ libzstd : $(LIBZSTD) lib: libzstd.a libzstd clean: - @rm -f core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc - @rm -f decompress/*.o + @$(RM) -f core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc dll/libzstd.dll dll/libzstd.lib + @$(RM) -f decompress/*.o @echo Cleaning library completed #------------------------------------------------------------------------ diff --git a/tests/Makefile b/tests/Makefile index d3a280e58..e2e8e0881 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -82,6 +82,14 @@ fullbench : $(ZSTD_FILES) $(PRGDIR)/datagen.c fullbench.c fullbench32 : $(ZSTD_FILES) $(PRGDIR)/datagen.c fullbench.c $(CC) -m32 $(FLAGS) $^ -o $@$(EXT) +fullbench-lib: $(PRGDIR)/datagen.c fullbench.c + $(MAKE) -C $(ZSTDDIR) libzstd.a + $(CC) $(FLAGS) $^ -o $@$(EXT) $(ZSTDDIR)/libzstd.a + +fullbench-dll: $(PRGDIR)/datagen.c fullbench.c + $(MAKE) -C $(ZSTDDIR) libzstd + $(CC) $(FLAGS) $^ -o $@$(EXT) -DZSTD_DLL_IMPORT=1 $(ZSTDDIR)/dll/libzstd.dll + fuzzer : CPPFLAGS += -I$(ZSTDDIR)/dictBuilder fuzzer : $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c fuzzer.c $(CC) $(FLAGS) $^ -o $@$(EXT) From cc3887085f938464ad0cad34b6b0e4c0b7f1bf05 Mon Sep 17 00:00:00 2001 From: Przemyslaw Skibinski Date: Mon, 21 Nov 2016 13:58:58 +0100 Subject: [PATCH 06/10] updated build\README.md --- .gitignore | 3 ++- build/.gitignore | 1 + build/README.md | 33 +++++++++++++++++++++++++++++++++ tests/Makefile | 1 + tests/fullbench.c | 21 ++++++++++++++------- 5 files changed, 51 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 6f792e615..796a696d3 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,5 @@ _zstdbench/ googletest/ *.d -build/VS2010/zwrapbench/zwrapbench.vcxproj \ No newline at end of file +# Directories +bin/ diff --git a/build/.gitignore b/build/.gitignore index 51fed59bb..f03aac8b3 100644 --- a/build/.gitignore +++ b/build/.gitignore @@ -11,6 +11,7 @@ VS2005/ VS2008/ VS2010/bin/ +VS2010/zwrapbench/ VS2012/bin/ VS2013/bin/ VS2015/bin/ diff --git a/build/README.md b/build/README.md index 8dc67326b..c4abe9efd 100644 --- a/build/README.md +++ b/build/README.md @@ -21,3 +21,36 @@ The following projects are included with the zstd distribution: 6. Change `Debug` to `Release` and if you have 64-bit Windows change also `Win32` to `x64`. 7. Press F7 on keyboard or select `BUILD` from the menu bar and choose `Build Solution`. 8. If compilation will be fine a compiled executable will be in `projects\VS2010\bin\x64\Release\zstd.exe` + + +#### Projects available within zstd.sln + +The Visual Studio solution file `visual\VS2010\zstd.sln` contains many projects that will be compiled to the +`visual\VS2010\bin\$(Platform)_$(Configuration)` directory. For example `zstd` set to `x64` and +`Release` will be compiled to `visual\VS2010\bin\x64_Release\zstd.exe`. The solution file contains the +following projects: + +- `zstd` : Command Line Utility, supporting gzip-like arguments +- `datagen` : Synthetic and parametrable data generator, for tests +- `fullbench` : Precisely measure speed for each zstd inner functions +- `fuzzer` : Test tool, to check zstd integrity on target platform +- `libzstd` : A static ZSTD library compiled to `libzstd_static.lib` +- `libzstd-dll` : A dynamic ZSTD library (DLL) compiled to `libzstd.dll` with the import library `libzstd.lib` +- `fullbench-dll` : The fullbench program compiled with the import library; the executable requires ZSTD DLL + + +#### Using ZSTD DLL with Microsoft Visual C++ project + +The header file `lib\zstd.h` and the import library +`visual\VS2010\bin\$(Platform)_$(Configuration)\libzstd.lib` are required to compile +a project using Visual C++. + +1. The path to header files should be added to `Additional Include Directories` that can + be found in Project Properties of Visual Studio IDE in the `C/C++` Property Pages on the `General` page. +2. The import library has to be added to `Additional Dependencies` that can + be found in Project Properties in the `Linker` Property Pages on the `Input` page. + If one will provide only the name `libzstd.lib` without a full path to the library + then the directory has to be added to `Linker\General\Additional Library Directories`. + +The compiled executable will require ZSTD DLL which is available at +`visual\VS2010\bin\$(Platform)_$(Configuration)\libzstd.dll`. diff --git a/tests/Makefile b/tests/Makefile index e2e8e0881..7e5c66ad8 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -132,6 +132,7 @@ clean: @$(RM) -f core *.o tmp* result* *.gcda dictionary *.zst \ $(PRGDIR)/zstd$(EXT) $(PRGDIR)/zstd32$(EXT) \ fullbench$(EXT) fullbench32$(EXT) \ + fullbench-lib$(EXT) fullbench-dll$(EXT) \ fuzzer$(EXT) fuzzer32$(EXT) zbufftest$(EXT) zbufftest32$(EXT) \ zstreamtest$(EXT) zstreamtest32$(EXT) \ datagen$(EXT) paramgrill$(EXT) roundTripCrash$(EXT) diff --git a/tests/fullbench.c b/tests/fullbench.c index 46af8172a..233b4e931 100644 --- a/tests/fullbench.c +++ b/tests/fullbench.c @@ -17,11 +17,16 @@ #include /* clock_t, clock, CLOCKS_PER_SEC */ #include "mem.h" -#include "zstd_internal.h" /* ZSTD_blockHeaderSize, blockType_e, KB, MB */ -#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressBegin, ZSTD_compressContinue, etc. */ +#ifndef ZSTD_DLL_IMPORT + #include "zstd_internal.h" /* ZSTD_blockHeaderSize, blockType_e, KB, MB */ + #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressBegin, ZSTD_compressContinue, etc. */ +#else + #define KB *(1 <<10) + #define MB *(1 <<20) + #define GB *(1U<<30) + typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e; +#endif #include "zstd.h" /* ZSTD_VERSION_STRING */ -#define FSE_STATIC_LINKING_ONLY /* FSE_DTABLE_SIZE_U32 */ -#include "fse.h" #include "datagen.h" @@ -111,8 +116,8 @@ size_t local_ZSTD_decompress(void* dst, size_t dstSize, void* buff2, const void* return ZSTD_decompress(dst, dstSize, buff2, g_cSize); } -static ZSTD_DCtx* g_zdc = NULL; #ifndef ZSTD_DLL_IMPORT +static ZSTD_DCtx* g_zdc = NULL; extern size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* ctx, const void* src, size_t srcSize); size_t local_ZSTD_decodeLiteralsBlock(void* dst, size_t dstSize, void* buff2, const void* src, size_t srcSize) { @@ -165,6 +170,7 @@ static size_t local_ZSTD_decompressStream(void* dst, size_t dstCapacity, void* b return buffOut.pos; } +#ifndef ZSTD_DLL_IMPORT static ZSTD_CCtx* g_zcc = NULL; size_t local_ZSTD_compressContinue(void* dst, size_t dstCapacity, void* buff2, const void* src, size_t srcSize) { @@ -194,6 +200,7 @@ size_t local_ZSTD_decompressContinue(void* dst, size_t dstCapacity, void* buff2, return regeneratedSize; } +#endif /*_******************************************************* @@ -217,13 +224,13 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb) case 2: benchFunction = local_ZSTD_decompress; benchName = "ZSTD_decompress"; break; +#ifndef ZSTD_DLL_IMPORT case 11: benchFunction = local_ZSTD_compressContinue; benchName = "ZSTD_compressContinue"; break; case 12: benchFunction = local_ZSTD_decompressContinue; benchName = "ZSTD_decompressContinue"; break; -#ifndef ZSTD_DLL_IMPORT case 31: benchFunction = local_ZSTD_decodeLiteralsBlock; benchName = "ZSTD_decodeLiteralsBlock"; break; @@ -256,6 +263,7 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb) case 2: g_cSize = ZSTD_compress(buff2, dstBuffSize, src, srcSize, 1); break; +#ifndef ZSTD_DLL_IMPORT case 11 : if (g_zcc==NULL) g_zcc = ZSTD_createCCtx(); break; @@ -263,7 +271,6 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb) if (g_zdc==NULL) g_zdc = ZSTD_createDCtx(); g_cSize = ZSTD_compress(buff2, dstBuffSize, src, srcSize, 1); break; -#ifndef ZSTD_DLL_IMPORT case 31: /* ZSTD_decodeLiteralsBlock */ if (g_zdc==NULL) g_zdc = ZSTD_createDCtx(); { blockProperties_t bp; From b85f7677433f7f16e8ef72956086312ef3604746 Mon Sep 17 00:00:00 2001 From: Przemyslaw Skibinski Date: Mon, 21 Nov 2016 14:10:55 +0100 Subject: [PATCH 07/10] files to generate ZSTD Windows binary package --- lib/dll/example/Makefile | 47 +++++++ lib/dll/example/README.md | 69 ++++++++++ lib/dll/example/build_package.bat | 17 +++ lib/dll/example/fullbench-dll.sln | 25 ++++ lib/dll/example/fullbench-dll.vcxproj | 179 ++++++++++++++++++++++++++ 5 files changed, 337 insertions(+) create mode 100644 lib/dll/example/Makefile create mode 100644 lib/dll/example/README.md create mode 100644 lib/dll/example/build_package.bat create mode 100644 lib/dll/example/fullbench-dll.sln create mode 100644 lib/dll/example/fullbench-dll.vcxproj diff --git a/lib/dll/example/Makefile b/lib/dll/example/Makefile new file mode 100644 index 000000000..36041a0e3 --- /dev/null +++ b/lib/dll/example/Makefile @@ -0,0 +1,47 @@ +# ########################################################################## +# Copyright (c) 2016-present, Yann Collet, Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. An additional grant +# of patent rights can be found in the PATENTS file in the same directory. +# ########################################################################## + +VOID := /dev/null +ZSTDDIR := ../include +LIBDIR := ../static +DLLDIR := ../dll + +CFLAGS ?= -O3 # can select custom flags. For example : CFLAGS="-O2 -g" make +CFLAGS += -Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow -Wswitch-enum \ + -Wdeclaration-after-statement -Wstrict-prototypes \ + -Wpointer-arith -Wstrict-aliasing=1 +CFLAGS += $(MOREFLAGS) +CPPFLAGS:= -I$(ZSTDDIR) -DXXH_NAMESPACE=ZSTD_ +FLAGS := $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) + + +# Define *.exe as extension for Windows systems +ifneq (,$(filter Windows%,$(OS))) +EXT =.exe +else +EXT = +endif + +.PHONY: default fullbench-dll fullbench-lib + + +default: all + +all: fullbench-dll fullbench-lib + + +fullbench-lib: fullbench.c datagen.c + $(CC) $(FLAGS) $^ -o $@$(EXT) $(LIBDIR)/libzstd_static.lib + +fullbench-dll: fullbench.c datagen.c + $(CC) $(FLAGS) $^ -o $@$(EXT) -DZSTD_DLL_IMPORT=1 $(DLLDIR)/libzstd.dll + +clean: + @$(RM) fullbench-dll$(EXT) fullbench-lib$(EXT) \ + @echo Cleaning completed diff --git a/lib/dll/example/README.md b/lib/dll/example/README.md new file mode 100644 index 000000000..34d19855c --- /dev/null +++ b/lib/dll/example/README.md @@ -0,0 +1,69 @@ +ZSTD Windows binary package +==================================== + +#### The package contents + +- `zstd.exe` : Command Line Utility, supporting gzip-like arguments +- `dll\libzstd.dll` : The DLL of ZSTD library +- `dll\libzstd.lib` : The import library of ZSTD library for Visual C++ +- `example\` : The example of usage of ZSTD library +- `include\` : Header files required with ZSTD library +- `static\libzstd_static.lib` : The static ZSTD library + + +#### Usage of Command Line Interface + +Command Line Interface (CLI) supports gzip-like arguments. +By default CLI takes an input file and compresses it to an output file: +``` + Usage: zstd [arg] [input] [output] +``` +The full list of commands for CLI can be obtained with `-h` or `-H`. The ratio can +be improved with commands from `-3` to `-16` but higher levels also have slower +compression. CLI includes in-memory compression benchmark module with compression +levels starting from `-b` and ending with `-e` with iteration time of `-i` seconds. +CLI supports aggregation of parameters i.e. `-b1`, `-e18`, and `-i1` can be joined +into `-b1e18i1`. + + +#### The example of usage of static and dynamic ZSTD libraries with gcc/MinGW + +Use `cd example` and `make` to build `fullbench-dll` and `fullbench-lib`. +`fullbench-dll` uses a dynamic ZSTD library from the `dll` directory. +`fullbench-lib` uses a static ZSTD library from the `lib` directory. + + +#### Using ZSTD DLL with gcc/MinGW + +The header files from `include\` and the dynamic library `dll\libzstd.dll` +are required to compile a project using gcc/MinGW. +The dynamic library has to be added to linking options. +It means that if a project that uses ZSTD consists of a single `test-dll.c` +file it should be compiled with "libzstd.dll". For example: +``` + gcc $(CFLAGS) -Iinclude\ test-dll.c -o test-dll dll\libzstd.dll +``` +The compiled executable will require ZSTD DLL which is available at `dll\libzstd.dll`. + + +#### The example of usage of static and dynamic ZSTD libraries with Visual C++ + +Open `example\fullbench-dll.sln` to compile `fullbench-dll` that uses a +dynamic ZSTD library from the `dll` directory. The solution works with Visual C++ +2010 or newer. When one will open the solution with Visual C++ newer than 2010 +then the solution will upgraded to the current version. + + +#### Using ZSTD DLL with Visual C++ + +The header files from `include\` and the import library `dll\libzstd.lib` +are required to compile a project using Visual C++. + +1. The path to header files should be added to `Additional Include Directories` that can + be found in project properties `C/C++` then `General`. +2. The import library has to be added to `Additional Dependencies` that can + be found in project properties `Linker` then `Input`. + If one will provide only the name `libzstd.lib` without a full path to the library + the directory has to be added to `Linker\General\Additional Library Directories`. + +The compiled executable will require ZSTD DLL which is available at `dll\libzstd.dll`. diff --git a/lib/dll/example/build_package.bat b/lib/dll/example/build_package.bat new file mode 100644 index 000000000..ce738a56c --- /dev/null +++ b/lib/dll/example/build_package.bat @@ -0,0 +1,17 @@ +@ECHO OFF +MKDIR bin\dll bin\static bin\example bin\include +COPY tests\fullbench.c bin\example\ +COPY programs\datagen.c bin\example\ +COPY programs\datagen.h bin\example\ +COPY programs\util.h bin\example\ +COPY lib\common\mem.h bin\example\ +COPY lib\common\zstd_errors.h bin\example\ +COPY lib\common\zstd_internal.h bin\example\ +COPY lib\common\error_private.h bin\example\ +COPY lib\zstd.h bin\include\ +COPY lib\libzstd.a bin\static\libzstd_static.lib +COPY lib\dll\libzstd.* bin\dll\ +COPY lib\dll\example\Makefile bin\example\ +COPY lib\dll\example\fullbench-dll.* bin\example\ +COPY lib\dll\example\README.md bin\ +COPY programs\zstd.exe bin\zstd.exe diff --git a/lib/dll/example/fullbench-dll.sln b/lib/dll/example/fullbench-dll.sln new file mode 100644 index 000000000..72e302e7f --- /dev/null +++ b/lib/dll/example/fullbench-dll.sln @@ -0,0 +1,25 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 2012 for Windows Desktop +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fullbench-dll", "fullbench-dll.vcxproj", "{13992FD2-077E-4954-B065-A428198201A9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {13992FD2-077E-4954-B065-A428198201A9}.Debug|Win32.ActiveCfg = Debug|Win32 + {13992FD2-077E-4954-B065-A428198201A9}.Debug|Win32.Build.0 = Debug|Win32 + {13992FD2-077E-4954-B065-A428198201A9}.Debug|x64.ActiveCfg = Debug|x64 + {13992FD2-077E-4954-B065-A428198201A9}.Debug|x64.Build.0 = Debug|x64 + {13992FD2-077E-4954-B065-A428198201A9}.Release|Win32.ActiveCfg = Release|Win32 + {13992FD2-077E-4954-B065-A428198201A9}.Release|Win32.Build.0 = Release|Win32 + {13992FD2-077E-4954-B065-A428198201A9}.Release|x64.ActiveCfg = Release|x64 + {13992FD2-077E-4954-B065-A428198201A9}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/lib/dll/example/fullbench-dll.vcxproj b/lib/dll/example/fullbench-dll.vcxproj new file mode 100644 index 000000000..3faacbae1 --- /dev/null +++ b/lib/dll/example/fullbench-dll.vcxproj @@ -0,0 +1,179 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {00000000-1CC8-4FD7-9281-6B8DBB9D3DF8} + Win32Proj + fullbench-dll + $(SolutionDir)bin\$(Platform)_$(Configuration)\ + $(SolutionDir)bin\obj\$(RootNamespace)_$(Platform)_$(Configuration)\ + + + + Application + true + MultiByte + + + Application + true + MultiByte + + + Application + false + true + MultiByte + + + Application + false + true + MultiByte + + + + + + + + + + + + + + + + + + + true + $(IncludePath);$(SolutionDir)..\..\lib;$(SolutionDir)..\..\programs;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib\common;$(UniversalCRT_IncludePath); + false + + + true + $(IncludePath);$(SolutionDir)..\..\lib;$(SolutionDir)..\..\programs;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib\common;$(UniversalCRT_IncludePath); + false + + + false + $(IncludePath);$(SolutionDir)..\..\lib;$(SolutionDir)..\..\programs;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib\common;$(UniversalCRT_IncludePath); + false + + + false + $(IncludePath);$(SolutionDir)..\..\lib;$(SolutionDir)..\..\programs;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib\common;$(UniversalCRT_IncludePath); + false + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;ZSTD_DLL_IMPORT=1;%(PreprocessorDefinitions) + true + false + ..\include + + + Console + true + $(SolutionDir)..\dll;%(AdditionalLibraryDirectories) + libzstd.lib;%(AdditionalDependencies) + + + + + + + Level4 + Disabled + WIN32;_DEBUG;_CONSOLE;ZSTD_DLL_IMPORT=1;%(PreprocessorDefinitions) + true + false + ..\include + + + Console + true + $(SolutionDir)..\dll;%(AdditionalLibraryDirectories) + libzstd.lib;%(AdditionalDependencies) + + + + + Level4 + + + MaxSpeed + true + true + WIN32;_DEBUG;_CONSOLE;ZSTD_DLL_IMPORT=1;%(PreprocessorDefinitions) + false + ..\include + false + MultiThreaded + + + Console + true + true + true + $(SolutionDir)..\dll;%(AdditionalLibraryDirectories) + libzstd.lib;%(AdditionalDependencies) + + + + + Level4 + + + MaxSpeed + true + true + WIN32;_DEBUG;_CONSOLE;ZSTD_DLL_IMPORT=1;%(PreprocessorDefinitions) + false + false + ..\include + MultiThreaded + + + Console + true + true + true + $(SolutionDir)..\dll;%(AdditionalLibraryDirectories) + libzstd.lib;%(AdditionalDependencies) + + + + + + + + + + + + + \ No newline at end of file From 62d19a6f39655578534999bc23dc673271ebff36 Mon Sep 17 00:00:00 2001 From: Przemyslaw Skibinski Date: Mon, 21 Nov 2016 14:22:08 +0100 Subject: [PATCH 08/10] lib\README.md: added Using MinGW+MSYS to create DLL --- lib/README.md | 16 ++++++++++++++++ lib/dll/example/README.md | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/README.md b/lib/README.md index d321f06b3..d33ad52c2 100644 --- a/lib/README.md +++ b/lib/README.md @@ -43,6 +43,22 @@ Other optional functionalities provided are : For example, advanced API for version `v0.4` is in `legacy/zstd_v04.h` . +#### Using MinGW+MSYS to create DLL + +DLL can be created using MinGW+MSYS with the `make libzstd` command. +This command creates `dll\libzstd.dll` and the import library `dll\libzstd.lib`. +The import library is only required with Visual C++. +The header file `zstd.h` and the dynamic library `dll\libzstd.dll` are required to +compile a project using gcc/MinGW. +The dynamic library has to be added to linking options. +It means that if a project that uses ZSTD consists of a single `test-dll.c` +file it should be linked with `dll\libzstd.dll`. For example: +``` + gcc $(CFLAGS) -Iinclude/ test-dll.c -o test-dll dll\libzstd.dll +``` +The compiled executable will require ZSTD DLL which is available at `dll\libzstd.dll`. + + #### Obsolete streaming API Streaming is now provided within `zstd.h`. diff --git a/lib/dll/example/README.md b/lib/dll/example/README.md index 34d19855c..957a29f35 100644 --- a/lib/dll/example/README.md +++ b/lib/dll/example/README.md @@ -39,7 +39,7 @@ The header files from `include\` and the dynamic library `dll\libzstd.dll` are required to compile a project using gcc/MinGW. The dynamic library has to be added to linking options. It means that if a project that uses ZSTD consists of a single `test-dll.c` -file it should be compiled with "libzstd.dll". For example: +file it should be linked with `dll\libzstd.dll`. For example: ``` gcc $(CFLAGS) -Iinclude\ test-dll.c -o test-dll dll\libzstd.dll ``` From eec700a3b764e137bdec9546dda21c576fa5f724 Mon Sep 17 00:00:00 2001 From: Przemyslaw Skibinski Date: Mon, 21 Nov 2016 14:34:03 +0100 Subject: [PATCH 09/10] exclude zbuff_compress.c and zbuff_decompress.c --- build/VS2008/fullbench/fullbench.vcproj | 12 ------------ build/VS2008/fuzzer/fuzzer.vcproj | 4 ---- build/VS2008/zstd/zstd.vcproj | 16 ---------------- build/VS2008/zstdlib/zstdlib.vcproj | 16 ---------------- lib/Makefile | 5 ++++- 5 files changed, 4 insertions(+), 49 deletions(-) diff --git a/build/VS2008/fullbench/fullbench.vcproj b/build/VS2008/fullbench/fullbench.vcproj index 8fe4f109c..0734219b4 100644 --- a/build/VS2008/fullbench/fullbench.vcproj +++ b/build/VS2008/fullbench/fullbench.vcproj @@ -364,14 +364,6 @@ RelativePath="..\..\..\lib\decompress\huf_decompress.c" > - - - - @@ -426,10 +418,6 @@ RelativePath="..\..\..\lib\common\mem.h" > - - diff --git a/build/VS2008/fuzzer/fuzzer.vcproj b/build/VS2008/fuzzer/fuzzer.vcproj index 3644b8c75..311b79909 100644 --- a/build/VS2008/fuzzer/fuzzer.vcproj +++ b/build/VS2008/fuzzer/fuzzer.vcproj @@ -430,10 +430,6 @@ RelativePath="..\..\..\lib\common\xxhash.h" > - - diff --git a/build/VS2008/zstd/zstd.vcproj b/build/VS2008/zstd/zstd.vcproj index 1d51f51cf..ad64f8696 100644 --- a/build/VS2008/zstd/zstd.vcproj +++ b/build/VS2008/zstd/zstd.vcproj @@ -380,14 +380,6 @@ RelativePath="..\..\..\lib\common\xxhash.c" > - - - - @@ -482,14 +474,6 @@ RelativePath="..\..\..\lib\common\xxhash.h" > - - - - diff --git a/build/VS2008/zstdlib/zstdlib.vcproj b/build/VS2008/zstdlib/zstdlib.vcproj index 9c61e9494..b1c103e32 100644 --- a/build/VS2008/zstdlib/zstdlib.vcproj +++ b/build/VS2008/zstdlib/zstdlib.vcproj @@ -360,14 +360,6 @@ RelativePath="..\..\..\lib\common\xxhash.c" > - - - - @@ -458,14 +450,6 @@ RelativePath="..\..\..\lib\common\xxhash.h" > - - - - diff --git a/lib/Makefile b/lib/Makefile index 681c048c6..8f316aa68 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -31,7 +31,10 @@ CFLAGS += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 \ FLAGS = $(CPPFLAGS) $(CFLAGS) $(MOREFLAGS) -ZSTD_FILES := common/*.c compress/*.c decompress/*.c dictBuilder/*.c +ZSTD_FILES := $(wildcard common/*.c compress/*.c decompress/*.c dictBuilder/*.c) +ZSTD_EXCLUDE := compress/zbuff_compress.c decompress/zbuff_decompress.c +ZSTD_FILES := $(filter-out $(ZSTD_EXCLUDE), $(ZSTD_FILES)) + ifeq ($(ZSTD_LEGACY_SUPPORT), 0) CPPFLAGS += -DZSTD_LEGACY_SUPPORT=0 From de4b4fc36f7e6e16956f2740e88b579f8f5d9dc2 Mon Sep 17 00:00:00 2001 From: Przemyslaw Skibinski Date: Mon, 21 Nov 2016 15:03:05 +0100 Subject: [PATCH 10/10] zlibWrapper: added XXH_NAMESPACE --- zlibWrapper/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zlibWrapper/Makefile b/zlibWrapper/Makefile index 48dc1a5b6..2503f0d7f 100644 --- a/zlibWrapper/Makefile +++ b/zlibWrapper/Makefile @@ -16,7 +16,7 @@ EXAMPLE_PATH = examples PROGRAMS_PATH = ../programs TEST_FILE = ../doc/zstd_compression_format.md -CPPFLAGS = -I$(PROGRAMS_PATH) -I$(ZSTDLIBDIR) -I$(ZSTDLIBDIR)/common -I$(ZLIBWRAPPER_PATH) +CPPFLAGS = -DXXH_NAMESPACE=XXH_ -I$(PROGRAMS_PATH) -I$(ZSTDLIBDIR) -I$(ZSTDLIBDIR)/common -I$(ZLIBWRAPPER_PATH) CFLAGS ?= $(MOREFLAGS) -O3 -std=gnu99 CFLAGS += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes -Wstrict-aliasing=1 -Wundef