How to switch from Apple to Homebrew-installed clang?

Viewed 5168

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?

1 Answers

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++.

Related