1

I am trying to install RcppMP in MacOS. However, when I type:

remotes::install_github("Thell/RcppMP",dependencies = T) 

I get the following error:

* installing *source* package ‘RcppMP’ ...
** using staged installation
** libs
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include/ -I'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/BH/include' -I'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include' -I/usr/local/include   -fPIC  -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
In file included from RcppExports.cpp:4:
In file included from ./../inst/include/RcppMP.h:7:
In file included from ../inst/include/RcppMP_RcppExports.h:7:
../inst/include/RcppMP_types.hpp:15:10: fatal error: 'mpreal.h' file not found
#include <mpreal.h>
         ^~~~~~~~~~
1 error generated.
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘RcppMP’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppMP’
Warning message:
In i.p(...) :
  installation of package ‘/var/folders/pq/hxwd9my563q_qpy4rbrlgkmw0000gn/T//RtmpIdnyiB/file2184610d74ea/RcppMP_0.1.1.tar.gz’ had non-zero exit status

My ~/.R/Makevars file contain the following specifications:

    CC=/usr/local/opt/llvm/bin/clang
    CXX=/usr/local/opt/llvm/bin/clang++
    CXX1X=/usr/local/opt/llvm/bin/clang++
    LDFLAGS=-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib
    CXXFLAGS=-I/usr/local/opt/llvm/include
    FLIBS=-L/usr/local/Cellar/gcc/11.3.0_1/lib/gcc/11
CafféSospeso
  • 1,101
  • 3
  • 11
  • 28
  • Try installing the [GNU mpfr library](https://www.mpfr.org/) (easiest method is via homebrew: `brew install mpfr`) and add "-I/usr/local/include" to your CXXFLAGS variable (i.e. `CXXFLAGS=-I/usr/local/opt/llvm/include -I/usr/local/include`) and add "-L/usr/local/lib" to your LDFLAGS variable (`-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib -L/usr/local/lib`). You may also need to install the gmp library (`brew install gmp`); see https://stackoverflow.com/questions/65251887/clang-7-error-linker-command-failed-with-exit-code-1-for-macos-big-sur/65334247#65334247 for more details – jared_mamrot Jun 06 '22 at 02:17
  • So I did try to do as you suggested, adding those lines to the `~/.R/Makevars` but I do get the same error. I made sure that both `mpfr` and `gmp` were installed. – CafféSospeso Jun 06 '22 at 05:49
  • Thanks for providing all the necessary details; I think I've figured it out. I got it to install successfully on my system so I'll post the steps I used as an answer – jared_mamrot Jun 06 '22 at 06:38
  • Rcpp maintainer here: I don't see why this is tagged `Rcpp`. It is mostly a 'how do I compile from source on macOS' question as best as I can tell. – Dirk Eddelbuettel Jun 06 '22 at 12:36
  • Hi @DirkEddelbuettel. Thanks for the comment. I am going to remove the Rcpp tag. – CafféSospeso Jun 06 '22 at 16:57

1 Answers1

2

This was a bit more complicated than I thought; this package requires mpfr, gmp and the very-similarly-named mpfrc++. The steps that worked for me are:

  1. Install gmp and mpfr via homebrew

  2. Download and unzip "mpfrc++-3.6.8.zip" from http://www.holoborodko.com/pavel/mpfr/#download

  3. Copy the mpreal header file ("mpreal.h") to /usr/local/include (sudo cp ./mpreal.h /usr/local/include/) or, in your case, perhaps sudo cp ./mpreal.h /usr/local/opt/llvm/include would make more sense

  4. Install/compile RcppMP (remotes::install_github("Thell/RcppMP",dependencies = TRUE))

I got some warnings but no errors, and the package loaded (library(RcppMP)), so I'm relatively confident it installed successfully. If you find otherwise, please let me know and I'll look into it further.

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
  • Your suggestion helped to solve the problem. However, I needed to use the `~/.R/Makevars` from here https://stackoverflow.com/questions/65251887/clang-7-error-linker-command-failed-with-exit-code-1-for-macos-big-sur/65334247#65334247, with the modifications you suggested. Do you know why clang compilation does not work whereas g++ does work? (if this is the true issue in my case). – CafféSospeso Jun 06 '22 at 17:06
  • I wrote [the post you got your `~/.R/Makevars` from](https://stackoverflow.com/questions/65251887/clang-7-error-linker-command-failed-with-exit-code-1-for-macos-big-sur/65334247#65334247) and the whole point of that post was to develop a strategy that worked for 'tricky edge cases'. I think this RcppMP package falls into the 'tricky edge case' category. There is a good chance you could compile it using clang, but you would need to spend time working out the compiler flags etc. Also, you would probably then need to adjust your `~/.R/Makevars` for other packages. Seems easier to just use g++. – jared_mamrot Jun 06 '22 at 23:39
  • Hi @jared_mamrot, yes I noticed that you wrote that post. I added that comment above just to be clear (also for others that may encounter the same problem). That is, I could install RcppMP using g++ and not clang. Thanks again for the help. – CafféSospeso Jun 06 '22 at 23:44
  • 1
    That makes sense; thanks for clarifying. I'm glad you solved your problem, and I'm glad I could help. this type of 'something isn't quite right' problem can be incredibly frustrating. Thanks for including all the relevant info in your post :) – jared_mamrot Jun 06 '22 at 23:52