Using OSX? Compiling an R package from source? Issues with ‘-fopenmp’? Try this.

You can file this one under “I may have the very specific solution if you’re having exactly the same problem.”

So: if you’re running some R code and you see a warning like this:

Warning message:
In checkMatrixPackageVersion() : Package version inconsistency detected.
TMB was built with Matrix version 1.2.14
Current Matrix version is 1.2.15
Please re-install 'TMB' from source using 
install.packages('TMB', type = 'source') or ask CRAN for a binary 
version of 'TMB' matching CRAN's 'Matrix' package

And installation of TMB from source fails like this:

install.packages("TMB", type = "source")
clang: error: unsupported option '-fopenmp'
make: *** [external_metis.o] Error 1
ERROR: compilation failed for package ‘TMB’

And you use Homebrew – first, do this:

brew install llvm

Then create the file ~/.R/Makevars, if it does not exist and edit its contents to look like this:

CC=/usr/local/opt/llvm/bin/clang
CXX=/usr/local/opt/llvm/bin/clang++

Your R package should now compile without error. If it works as it did for me :)

2 thoughts on “Using OSX? Compiling an R package from source? Issues with ‘-fopenmp’? Try this.

  1. Hi,
    I think the first line should be “CC” and not “C”, at least that’s what I had to do on my computer…
    Thanks for the tip!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s