How to Perform a Cross-Platform Build of Kanzi Using Visual Studio, GCC, or Clang
Build Kanzi using the pre-configured Visual Studio solutions for Windows, the Makefile in src/Makefile for GCC/Clang on Windows (MinGW), Linux, and macOS, or the CMake configuration for universal compilation.
Kanzi is a portable C++ lossless compression library maintained in the flanglet/kanzi-cpp repository. The project ships with a dual-mode build system—supporting both native Makefiles and CMake—that enables a cross-platform build of Kanzi without external dependencies on Windows, Linux, or macOS.
Building Kanzi with Visual Studio on Windows
The repository provides pre-generated Visual Studio solutions that compile the project without requiring Makefile knowledge.
Visual Studio 2022 and 2008 Solutions
Unzip the appropriate solution archive from the repository root:
- Visual Studio 2022 (64-bit):
Kanzi_VS2022.zip - Visual Studio 2008 (32-bit, no multithreading):
Kanzi_VS2008.zip
Open Kanzi.sln inside the extracted folder. The default Release configuration applies optimization flags matching the Makefile settings. According to src/Makefile lines 35-38, the project uses these flags:
CXXFLAGS += -c -std=$(CXX_STD) -fstrict-aliasing -Wall -Wextra -O3 -fomit-frame-pointer -fPIC -DNDEBUG -pedantic -march=native -fno-rtti $(CONCURRENCY_FLAG)
Build the Kanzi project (or Kanzi_static / Kanzi_dynamic configurations). The output kanzi.exe appears under bin\Release\.
Building Kanzi with GCC or Clang on Windows (MinGW)
For MinGW-w64 toolchains, use the provided Makefile directly from the src directory:
cd src
make clean
mingw32-make.exe kanzi
To create a statically linked binary:
mingw32-make.exe kanzi_static
The Makefile detects Windows via $(OS) == Windows_NT at lines 27-31. For x86_64 hosts, it selects architecture-specific flags at line 42. Multithreading requires GCC 5.0 or later, automatically linking -lpthread as defined at lines 10-13. The resulting binaries are placed in ../bin/ via the target at lines 202-204.
To use Clang instead of GCC, specify the compiler:
mingw32-make.exe CXX=clang++ kanzi
Building Kanzi on Linux and macOS
Navigate to the source directory and invoke the Makefile:
cd src
make clean
make kanzi
For a static executable (Linux only):
make kanzi_static
The Makefile detects the host OS using uname -s at line 30. Architecture-specific flags are chosen at lines 41-47 based on the detected platform. The default C++ standard is C++17 (CXX_STD = c++17 at line 20).
macOS Specific Considerations
When building on macOS (detected as Darwin at lines 40-44), the Makefile adjusts the shared library suffix to .dylib and uses the -dynamiclib link option at lines 42-44. Note that static linking is disabled on macOS; attempting to build kanzi_static will print a warning at lines 7-10.
CMake Cross-Platform Build
For a universal build method that works identically on Windows, Linux, and macOS:
mkdir build
cd build
cmake ..
make -j$(nproc)
On Windows with Visual Studio, use:
mkdir build && cd build
cmake ..
cmake --build . --config Release
The CMakeLists.txt wrapper at the repository root follows the same logic as the Makefile, selecting the OS, setting -std=c++17, adding -pthread, and enabling multithreading unless CONCURRENCY_DISABLED is defined. By default, this builds a dynamic executable; request a static binary with make kanzi_static after configuration.
Run the test suite to verify the build:
ctest
Build System Architecture
The dual-mode build system relies on specific source organization and platform detection logic.
Source Layout and Targets
All functional code resides under src/:
- Core library: Entropy codecs, transforms, and utilities compiled into
libkanzi.{a,so,dylib} - API layer:
src/api/Compressor.hppandsrc/api/Decompressor.hppprovide the public C++ interface - Application:
src/app/Kanzi.cppimplements the command-line wrapper
The Makefile defines source collections at lines 50-84 (LIB_COMMON_SOURCES, LIB_COMP_SOURCES, LIB_DECOMP_SOURCES). The OBJ_DIR variable at lines 15-22 preserves directory hierarchy for object files. Targets kanzi, kanzi_static, and kanzi_dynamic at lines 202-219 link objects using OS-specific suffixes (.exe, .so, .dll, .dylib).
Platform Detection and Flags
The DETECTED_OS variable is set via uname -s for Linux/macOS or the built-in $(OS) variable for Windows (lines 27-31). This value drives compiler flag selection, library suffixes, and install paths.
The Makefile defaults to c++17 but supports c++11, c++14, and c++20 via the CXX_STD variable. Key flags applied consistently across compilers include -fno-rtti, -DNDEBUG, -march=native, and -fstrict-aliasing (lines 35-44). The CONCURRENCY_DISABLED flag at line 16 disables multithreading; when enabled, the build links against pthread and uses the thread pool implementation in src/concurrent.hpp.
Summary
- Windows (Visual Studio): Unzip
Kanzi_VS2022.ziporKanzi_VS2008.zip, openKanzi.sln, and build the Release configuration. - Windows (MinGW): Run
mingw32-make.exe kanzifrom thesrcdirectory to compile with GCC or Clang. - Linux/macOS: Execute
make kanzifrom thesrcdirectory; usemake kanzi_staticfor static linking on Linux only. - Universal (CMake): Create a build directory, run
cmake .., and build withmakeorcmake --build. - The build system auto-detects the platform at
src/Makefilelines 27-31 and applies appropriate flags for C++17, threading, and architecture optimization.
Frequently Asked Questions
Can I build Kanzi on macOS as a completely static binary?
No. The src/Makefile explicitly disables static executable builds on macOS (detected as Darwin) and prints a warning at lines 7-10. You can build dynamic executables and shared libraries (.dylib) on macOS, but static linking of the final executable is not supported due to platform limitations.
How do I disable multithreading when building Kanzi?
Pass the CONCURRENCY_DISABLED flag when invoking make:
make kanzi CONCURRENCY_DISABLED=1
This defines -DCONCURRENCY_DISABLED at line 16 of the Makefile, removes the -lpthread linkage at lines 10-13, and compiles the library to run single-threaded using the fallback implementation in src/concurrent.hpp.
What C++ standard does Kanzi require?
The build system defaults to C++17 (CXX_STD = c++17 at line 20 of src/Makefile), but the code is compatible with C++11, C++14, and C++20. Override the standard by passing the variable to make:
make kanzi CXX_STD=c++11
Where is the command-line argument parsing implemented?
The main entry point and CLI option parsing are located in src/app/Kanzi.cpp. This file handles arguments such as -l for compression level, -i for input file, and -o for output file, then invokes the compressor and decompressor APIs defined in src/api/Compressor.hpp and src/api/Decompressor.hpp.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →