2020-04-03 13:23:32 +00:00
---
toc_priority: 66
2020-07-20 14:33:54 +00:00
toc_title: Build on Linux for Mac OS X
2020-04-03 13:23:32 +00:00
---
2020-03-20 10:10:48 +00:00
# How to Build ClickHouse on Linux for Mac OS X {#how-to-build-clickhouse-on-linux-for-mac-os-x}
2019-09-24 14:43:07 +00:00
2020-06-18 08:24:31 +00:00
This is for the case when you have 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 ](../development/build-osx.md ).
2019-11-02 08:59:30 +00:00
2020-06-18 08:24:31 +00:00
The cross-build for Mac OS X is based on the [Build instructions ](../development/build.md ), follow them first.
2019-09-24 14:43:07 +00:00
2020-07-20 14:33:54 +00:00
## Install Clang-8 {#install-clang-8}
2019-09-24 14:43:07 +00:00
Follow the instructions from https://apt.llvm.org/ for your Ubuntu or Debian setup.
For example the commands for Bionic are like:
2020-03-20 10:10:48 +00:00
``` bash
2019-09-24 14:43:07 +00:00
sudo echo "deb [trusted=yes] http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main" >> /etc/apt/sources.list
sudo apt-get install clang-8
```
2020-07-20 14:33:54 +00:00
## Install Cross-Compilation Toolset {#install-cross-compilation-toolset}
2019-09-24 14:43:07 +00:00
2020-03-20 10:10:48 +00:00
Let’ s remember the path where we install `cctools` as ${CCTOOLS}
2019-10-02 14:35:07 +00:00
2020-03-20 10:10:48 +00:00
``` bash
2019-10-02 14:35:07 +00:00
mkdir ${CCTOOLS}
2019-09-24 14:43:07 +00:00
git clone https://github.com/tpoechtrager/apple-libtapi.git
cd apple-libtapi
2019-10-02 14:35:07 +00:00
INSTALLPREFIX=${CCTOOLS} ./build.sh
2019-09-24 14:43:07 +00:00
./install.sh
cd ..
git clone https://github.com/tpoechtrager/cctools-port.git
cd cctools-port/cctools
2019-10-02 14:35:07 +00:00
./configure --prefix=${CCTOOLS} --with-libtapi=${CCTOOLS} --target=x86_64-apple-darwin
2019-09-24 14:43:07 +00:00
make install
2019-12-02 14:00:21 +00:00
```
2020-03-18 14:55:01 +00:00
Also, we need to download macOS X SDK into the working tree.
2019-09-24 14:43:07 +00:00
2020-03-20 10:10:48 +00:00
``` bash
2019-12-02 14:00:21 +00:00
cd ClickHouse
2019-12-15 05:51:39 +00:00
wget 'https://github.com/phracker/MacOSX-SDKs/releases/download/10.14-beta4/MacOSX10.14.sdk.tar.xz'
2019-12-15 05:53:21 +00:00
mkdir -p build-darwin/cmake/toolchain/darwin-x86_64
tar xJf MacOSX10.14.sdk.tar.xz -C build-darwin/cmake/toolchain/darwin-x86_64 --strip-components=1
2019-09-24 14:43:07 +00:00
```
2020-07-20 14:33:54 +00:00
## Build ClickHouse {#build-clickhouse}
2019-09-24 14:43:07 +00:00
2020-03-20 10:10:48 +00:00
``` bash
2019-09-24 14:43:07 +00:00
cd ClickHouse
mkdir build-osx
2019-12-02 14:00:21 +00:00
CC=clang-8 CXX=clang++-8 cmake . -Bbuild-osx -DCMAKE_TOOLCHAIN_FILE=cmake/darwin/toolchain-x86_64.cmake \
2019-10-02 14:35:07 +00:00
-DCMAKE_AR:FILEPATH=${CCTOOLS}/bin/x86_64-apple-darwin-ar \
-DCMAKE_RANLIB:FILEPATH=${CCTOOLS}/bin/x86_64-apple-darwin-ranlib \
2019-12-02 14:00:21 +00:00
-DLINKER_NAME=${CCTOOLS}/bin/x86_64-apple-darwin-ld
2019-09-24 14:43:07 +00:00
ninja -C build-osx
```
2020-03-20 10:10:48 +00:00
The resulting binary will have a Mach-O executable format and can’ t be run on Linux.