Oliver R
Oliver R

Reputation: 185

How to switch from Apple to Homebrew-installed clang?

I am trying to install a package on R called XBART. I use RStudio as my IDE, and am installing in the console: 'install_github("jingyuhe/XBART")'. The package requires a C++ compiler, and I am using clang++. However, I keep getting the following error:

clang: error: unsupported option '-fopenmp'

From searching around, it seems that the Apple clang doesn't support OpenMP, which is why I am getting this error. I've tried to install an outside clang ('brew install llvm') and OpenMP ('brew install libomp'). It keeps using the Apple version of clang for the download, though. How do I make R use this outside compiler for the download instead of the Apple version?

Upvotes: 16

Views: 26880

Answers (2)

user9773080
user9773080

Reputation:

Install your desired version:

brew install llvm@14

Then insert the following in ~/.zshrc (change versions if different):

PATH="/opt/homebrew/Cellar/llvm@14/14.0.6/bin${PATH:+:${PATH}}"; export PATH;

Upon opening a new shell, check the version:

clang --version
Homebrew clang version 14.0.6
Target: arm64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm@14/14.0.6/bin

Upvotes: 5

StPiere
StPiere

Reputation: 4243

You could install brew llvm/clang with:

brew update
brew install llvm

The highest clang version in brew is 10.0.1 at the moment of writing.

This will normally install llvm under /usr/local/opt/llvm for not to colide with the apple clang.

You can either set /usr/local/opt/llvm/bin in front of PATH or set CC and CXX environment variables appropriatelly.

On my machine I have compiled the newest LLVM from sources (version 12), installed it under /usr/local/opt/myllvm and set CC/CXX to clang/clang++.

Upvotes: 6

Related Questions