This guide illustrates the steps required to install the latest version of LLVM on MacOS Mojave using Homebrew.
1) Install Homebrew In order to install Homebrew, simply open a terminal instance and paste the following command:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2) Install LLVM The latest version of LLVM can be installed running the following command in the terminal:
brew install llvm
Once completed the installation, add LLVM to your path variable running the following command:
echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc # (zsh)
echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.bashrc # (bash)
3) Environment Variables In order to use build tools such as CMake or Make, specific environment variables must be properly updated targeting the new LLVM installation. Add the following assignments to your configuration file (.bashrc or .zshrc):
export CC=clang
export CXX=clang++
export LD=ld.lld
export AR=llvm-ar
export RANLIB=llvm-ranlib
4) Building LLVM projects LLVM projects can be compiled executing the following command from the root directory:
clang++ -g -O3 <<APP_CPP_FILE>> `llvm-config --cxxflags --ldflags --system-libs --libs core` -o <<APP_EXECUTABLE_NAME>>