Skip to content

Building

Petr Senichenkov edited this page Jan 8, 2025 · 4 revisions

Build instructions

Here are build instructions for different compilers. The following instructions were tested on Ubuntu 20.04+ LTS and macOS Sonoma 14.7+ (Apple Silicon).

The following compilers are currently supported:

  • Linux:
    • GNU GCC, version 10+
    • LLVM Clang, version 16+
  • macOS:
    • Apple Clang, version 15+
    • GNU GCC, version 10+
    • LLVM CLang, version 16+

Ubuntu dependencies installation

GCC

You can find build instructions for GCC on Ubuntu in README.md.

Clang

  1. Firstly, you'll need to build Boost with Clang, as packaged versions, distributed by package managers, are built with GCC and have different ABI. To do this, execute the following commands:
curl https://archives.boost.io/release/1.86.0/source/boost_1_86_0.tar.bz2 --output "boost_1_86_0.tar.bz2"
tar xvjf boost_1_86_0.tar.bz2 && rm boost_1_86_0.tar.bz2
cd boost_1_86_0
  1. Compile and install Boost:
./bootstrap.sh
sudo ./b2 install -a toolset=clang cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++"
  1. Run the following commands:
sudo apt install cmake git-lfs
bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
export CC=clang
export CXX=clang++
export CXXFLAGS="-stdlib=libc++"
# libc++ is fully compatible with GCC's ABI, so you can omit the next line if you want to use libstdc++ ABI:
export LDFLAGS="-lc++abi"

Second command installs the latest version of LLVM (which includes Clang). For other installation options, see LLVM packages page. The last 4 lines set Clang as CMake compiler in your terminal session and set all needed libraries. You can also add them to the end of ~/.profile to set this by default in all sessions.

macOS dependencies installation

Install Xcode Command Line Tools if you don't have them. Run:

xcode-select --install

Follow the prompts to continue.

To install CMake and python on macOS we recommend to use Homebrew package manager. With Homebrew installed, run the following commands:

brew install cmake python3

After installation, check cmake --version. If command is not found, then you need to add to environment path to homebrew installed packages. To do this open ~/.zprofile (for Zsh) or ~/.bash_profile (for Bash) and add to the end of the file the output of brew shellenv. After that, restart the terminal and check the version of CMake again, now it should be displayed.

Apple Clang

You can find build instructions for Apple CLang in README.md.

GCC

Install GCC using Homebrew:

brew install gcc@14

Then you need to install Boost library built with GCC. Please avoid using Homebrew for this, as the Boost version provided by Homebrew is built with Clang, which has a different ABI. Instead, download the latest version of Boost from the official website, open terminal and run:

cd ~/Downloads
curl https://archives.boost.io/release/1.86.0/source/boost_1_86_0.tar.bz2 --output "boost_1_86_0.tar.bz2"
tar xvjf boost_1_86_0.tar.bz2 && rm boost_1_86_0.tar.bz2
cd boost_1_86_0

Navigate to the unpacked Boost directory in the terminal and run the following commands:

./bootstrap.sh 
echo "using darwin : : g++-14 ;" > user-config.jam
sudo ./b2 install --user-config=user-config.jam --layout=versioned
export BOOST_ROOT=/usr/local/ # export Boost_ROOT=/usr/local/ for CMake 3.26 and below.

You can also add the last export with current path to ~/.zprofile or ~/.bash_profile to set this boost path by default.

Before building the project you must set locally or in the above-mentioned dotfiles the following CMake environment variables:

export CC=gcc-14
export CXX=g++-14
export SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/
export DYLD_LIBRARY_PATH=/usr/local/lib:${DYLD_LIBRARY_PATH}

The first two lines set GCC as the default compiler in CMake. The SDKROOT export is also necessary due to issues with GCC 14 and the last macOS 15 SDK used by CMake by default, you can read more about this here and here. The last export is the solution for dynamic linking with python module.

LLVM CLang

Instructions below are given for Clang-17. To use another version, replace llvm@17 with llvm@vv everywhere.

Install Clang using Homebrew:

brew install llvm@17

Then you need to install Boost library built with LLVM Clang. Please avoid using Homebrew for this, as the Boost version provided by Homebrew is built with Apple Clang, which has a different ABI. Instead, download the latest version of Boost from the official website and unpack the archive:

curl https://archives.boost.io/release/1.86.0/source/boost_1_86_0.tar.bz2 --output "boost_1_86_0.tar.bz2"
tar xvjf boost_1_86_0.tar.bz2
rm boost_1_86_0.tar.bz2
cd boost_1_86_0

Navigate to the unpacked Boost directory in the terminal and run the following commands:

./bootstrap.sh
echo "using darwin : : $(brew --prefix llvm@17)/bin/clang++ ;" > user-config.jam
sudo ./b2 install -a --prefix=/usr/local --user-config=user-config.jam \
 cxxflags="-std=c++11 -I$(brew --prefix llvm@17)/include" \
 linkflags="-L$(brew --prefix llvm@17)/lib/c++"
export BOOST_ROOT=/usr/local # export Boost_ROOT=/usr/local for CMake 3.26 and below.

You can also add the last export to ~/.zprofile or ~/.bash_profile to set this boost path by default.

Before building the project you must set locally or in the above-mentioned dotfiles the following CMake environment variables:

export CC=$(brew --prefix llvm@17)/bin/clang
export CXX=$(brew --prefix llvm@17)/bin/clang++
export CXXFLAGS="-I$(brew --prefix llvm@17)/include"
export LDFLAGS="-L$(brew --prefix llvm@17)/lib/c++ -L$(brew --prefix llvm@17)/lib/unwind -lunwind"

The first two lines set LLVM Clang as the default compiler in CMake. Other two lines tell Clang to use LLVM version of libc++.

Clone this wiki locally