Skip to content
Hajin Jang edited this page Sep 25, 2023 · 5 revisions

Dual-Linking Zlib-ng and Zlib

In order to link both zlib and zlib-ng in the same executable:

  • Define ZLIB_CONST in zlib
  • Compile without ZLIB_COMPAT in zlib-ng

Building with Configure on Apple Silicon

Export following environment variables before building on Apple silicon-based Macs:

export ARCH_FLAGS="-arch arm64"
export SDK_NAME=macosx
export SDK_PATH=$(xcrun --show-sdk-path --sdk $SDK_NAME)
export CFLAGS="$ARCH_FLAGS -isysroot $SDK_PATH -I$SDK_PATH/usr/include"
export CXXFLAGS=$CFLAGS
export LDFLAGS="$ARCH_FLAGS"
export CC="$(xcrun -sdk $SDK_PATH --find clang) $CFLAGS"
export CXX="$(xcrun -sdk $SDK_PATH --find clang++) $CXXFLAGS"
export LD="$(xcrun -sdk $SDK_PATH --find ld) $LDFLAGS"

$ ./configure
$ make
$ make test
$ make install

Building with MinGW toolchains

MinGW, Minimalist GNU for Windows, is a Windows port of the GCC.

Windows version of LLVM/Clang also supports the mingw frontend.

  • MinGW-w64: The de-facto GCC-based MinGW toolchain.
  • llvm-mingw: A LLVM/Clang/LLD based mingw-w64 toolchain.

MinGW CMake toolchain files

zlib-ng provides CMake toolchain files for mingw toolchains.

File Toolchain Target Architecture
toolchain-mingw-i686.cmake MinGW-w64 x86
toolchain-mingw-x86_64.cmake MinGW-w64 x64
toolchain-llvm-mingw-aarch64.cmake llvm-mingw arm64
toolchain-llvm-mingw-armv7.cmake llvm-mingw arm
toolchain-llvm-mingw-i686.cmake llvm-mingw x86
toolchain-llvm-mingw-x86_64.cmake llvm-mingw x64

To use these toolchain files, please pass the toolchain root path by:

  • Add mingw toolchain root to the PATH environment variable.
  • (llvm-mingw only) Append the -DLLVM_MINGW_ROOT=<TOOLCHAIN_ROOT> argument.
  • (llvm-mingw only) Set to LLVM_MINGW_ROOT environment variable.

Building with CMake on Windows Powershell

Scenario:

  • Building Windows arm64 binaries with llvm-mingw on Windows.
  • llvm-mingw is located at C:\Tools\llvm-mingw, and passed by the -DLLVM_MINGW_ROOT argument.
> cd zlib-ng
> mkdir build
> cd build
> cmake .. -G "MinGW Makefiles" `
"-DCMAKE_MAKE_PROGRAM=C:\Tools\llvm-mingw\bin\mingw32-make.exe" `
"-DCMAKE_TOOLCHAIN_FILE=..\cmake\toolchain-llvm-mingw-aarch64.cmake" `
"-DLLVM_MINGW_ROOT=C:\Tools\llvm-mingw"
> cmake --build . --config Release --parallel

Building with CMake on Linux

Scenario:

  • Building Windows i686 binaries with llvm-mingw on Linux.
  • llvm-mingw is located at ~/Tools/llvm-mingw-20230919-ucrt-ubuntu-20.04-x86_64, and passed by the $PATH environment variable.
$ export PATH=$HOME/Tools/llvm-mingw-20230919-ucrt-ubuntu-20.04-x86_64/bin:$PATH

$ cd zlib-ng
$ mkdir build
$ cd build
$ cmake .. -G "Unix Makefiles" \
"-DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain-llvm-mingw-i686.cmake"
$ cmake --build . --config Release --parallel