Error while compiling on sources

Hi there,

I am using R 4.0.1 on MacOS 10.15.10. I try to install mvtnorm() package. Unfortunately, I need the most current version. The binaries of mvtnorm() are build using R < 4. As such I need to install from source. Here is what I get

install.packages("mvtnorm")

  There is a binary version available but the source version is later:
        binary source needs_compilation
mvtnorm  1.1-0  1.1-1              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) y
installing the source package ‘mvtnorm’

trying URL 'https://cran.rstudio.com/src/contrib/mvtnorm_1.1-1.tar.gz'
Content type 'application/x-gzip' length 163902 bytes (160 KB)
==================================================
downloaded 160 KB

* installing *source* package ‘mvtnorm’ ...
** package ‘mvtnorm’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
/usr/local/Cellar/llvm/8.0.0_1/bin/clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c C_FORTRAN_interface.c -o C_FORTRAN_interface.o
In file included from C_FORTRAN_interface.c:8:
In file included from ./mvtnorm.h:2:
/Library/Frameworks/R.framework/Resources/include/R.h:55:11: fatal error: 'stdlib.h' file not found
# include <stdlib.h> /* Not used by R itself, but widely assumed in packages */
          ^~~~~~~~~~
1 error generated.
make: *** [C_FORTRAN_interface.o] Error 1
ERROR: compilation failed for package ‘mvtnorm’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/mvtnorm’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/mvtnorm’
Warning in install.packages :
  installation of package ‘mvtnorm’ had non-zero exit status

The downloaded source packages are in
	‘/private/var/folders/py/z1sgc8b17l5fp8pmrpnrjykm0000gn/T/Rtmpdrwvh2/downloaded_packages’
>

####

I already have the latest Xcode:
Profs-MacBook-Pro: xcode-select --install

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

Profs-MacBook-Pro: softwareupdate --install -a

Software Update Tool

Finding available software

No updates are available.

Any suggestion is welcome!
Best
Sven

Hi Sven,
I also had a Fortran-related error for the same situation. I had to install a Fortran compiler to install mvtnorm (https://mac.r-project.org/tools/).
Hope that helps,
Amy

Thank you so much. However, it did not work for me even with a Fortran compiler. Meanwhile, the binaries for mvtnorm are available for R > 4.
Best
Sven

Hi Sven,
It looks like the llvm compiler is unable to find the header file stdlib.h in the error message. I found this on one of the comments on the Coatless Professor's Blog: https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/

Here is an example of what I have in my ~/.R/Makevars file. In particular, I have specified the location of some of the header files installed as part of Xcode command line tools under CPPFLAGS

LLVM_LOC = /usr/local/opt/llvm
CC=$(LLVM_LOC)/bin/clang -fopenmp
CXX=$(LLVM_LOC)/bin/clang++ -fopenmp
# -O3 should be faster than -O2 (default) level optimisation ..
CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L/usr/local/opt/gettext/lib -L$(LLVM_LOC)/lib -Wl,-rpath,$(LLVM_LOC)/lib
CPPFLAGS=-I/usr/local/opt/gettext/include -I$(LLVM_LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include

Jim

Thank you so much as well, Jim.
Meanwhile the binaries got updated to R > 4.0.
However, I still face the problem with paralell computing, which seems to be a Studio bug: https://github.com/rstudio/rstudio/issues/6692

Best
Sven

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.