Skip to main content

How to Build ClickHouse on Linux for Mac OS X

This is for the case when you have a Linux machine and want to use it to build clickhouse binary that will run on OS X. This is intended for continuous integration checks that run on Linux servers. If you want to build ClickHouse directly on Mac OS X, then proceed with another instruction.

The cross-build for Mac OS X is based on the Build instructions, follow them first.

Install Clang-14

Follow the instructions from for your Ubuntu or Debian setup. For example the commands for Bionic are like:

sudo echo "deb [trusted=yes] llvm-toolchain-bionic-14 main" >> /etc/apt/sources.list
sudo apt-get install clang-14

Install Cross-Compilation Toolset

Let’s remember the path where we install cctools as ${CCTOOLS}

export CCTOOLS=$(cd ~/cctools && pwd)
mkdir ${CCTOOLS}

git clone
cd apple-libtapi
cd ..

git clone
cd cctools-port/cctools
./configure --prefix=$(readlink -f ${CCTOOLS}) --with-libtapi=$(readlink -f ${CCTOOLS}) --target=x86_64-apple-darwin
make install

Also, we need to download macOS X SDK into the working tree.

cd ClickHouse/cmake/toolchain/darwin-x86_64
curl -L '' | tar xJ --strip-components=1

Build ClickHouse

cd ClickHouse
mkdir build-darwin
cd build-darwin
CC=clang-14 CXX=clang++-14 cmake -DCMAKE_AR:FILEPATH=${CCTOOLS}/bin/x86_64-apple-darwin-ar -DCMAKE_INSTALL_NAME_TOOL=${CCTOOLS}/bin/x86_64-apple-darwin-install_name_tool -DCMAKE_RANLIB:FILEPATH=${CCTOOLS}/bin/x86_64-apple-darwin-ranlib -DLINKER_NAME=${CCTOOLS}/bin/x86_64-apple-darwin-ld -DCMAKE_TOOLCHAIN_FILE=cmake/darwin/toolchain-x86_64.cmake ..

The resulting binary will have a Mach-O executable format and can’t be run on Linux.