Building the rSPDE package from source on Mac and Linux
David Bolin and Alexandre B. Simas
Created: 2023-01-17. Last modified: 2024-12-20.
Source:vignettes/build_source.rmd
build_source.rmd
Building from source
To build rSPDE
from source you need to obtain the GitHub version. If you
have all the dependencies (see below how to install some of them), you
can install the rSPDE
package from source by running the
following command on R
(for the development version):
remotes::install_github("davidbolin/rspde", ref = "devel-src")
or, if you want to install the stable version:
remotes::install_github("davidbolin/rspde", ref = "stable-src")
Dependencies on Linux
The rSPDE
package depends on the Eigen C++
library.
To install Eigen on Ubuntu, run:
To install Eigen on Arch-Linux or Manjaro, run:
To install Eigen on Red Hat, Fedor or CentOS, run:
To install Eigen on OpenSuse, run:
Dependencies on Mac
We can install Eigen on MacOS with Homebrew.
To install Homebrew, run:
To install Eigen using Homebrew, run:
Finally, if after installing eigen
with
brew
it gives you an error that it cannot find
eigen
library, you can create a symbolic link to
eigen
’s path as:
You also need to create the following symbolic links related to homebrew:
sudo ln -s $(brew --prefix)/lib /usr/local/brewlib
sudo ln -s $(brew --prefix)/include /usr/local/brewinclude
Finally, you need to install gcc-14
:
and also create the symbolic links associated to
gcc
:
Adjusting the Makefile
If you experience trouble while installing the rSPDE
package, you might need to adjust the Makefile
. Before
that, you will need to have rSPDE
source files locally on
your computer. To such an end, you can, for instance, close the
rSPDE
repository by running the following command on a
terminal:
You can also download the source files.
Now, let us discuss the Makefile
. The
Makefile
has the following base form:
toInclude = ${R_LIBRARY_DIR}/INLA/include/
obj = cgeneric_mvnormdens.o cgeneric_aux_nonstat.o cgeneric_aux_nonstat_fixed.o \
cgeneric_rspde_stat_frac_model.o cgeneric_rspde_nonstat_general.o \
cgeneric_rspde_stat_general.o cgeneric_rspde_stat_parsim_gen.o \
cgeneric_rspde_stat_parsim_fixed.o cgeneric_rspde_stat_int.o \
cgeneric_rspde_nonstat_gen_fixed.o cgeneric_rspde_nonstat_int.o \
cgeneric_aux_nonstat_int.o
all : rSPDE.so
CC = clang
CXX = clang++
EIGEN_MAC = /usr/local/include/eigen3/
EIGEN_LINUX = /usr/include/eigen3/
flags = -O2 -Wall -Wextra -fpic
%.o: %.c
$(CC) $(flags) -Iinclude -I$(toInclude) -c $^ -o $@
%.o: %.cpp
$(CXX) $(flags) -I$(toInclude) -I$(EIGEN_MAC) -I$(EIGEN_LINUX) -c $^ -o $@
rSPDE.so: $(obj)
$(CXX) -shared *.o -o ../inst/shared/rspde_cgeneric_models.so -lblas -llapack
clean :
rm -f *.o
.PHONY: all clean
Adjusts on Linux
For linux, we recommend to use the gcc-12
and
g++-12
compilers. To this end, one must install
gcc
and g++
, then change the following lines
on the Makefile
:
One should also confirm the location of the Eigen library. The
default location is /usr/include/eigen3/
and is already set
at the Makefile. If you have Eigen installed in a different location,
you will need to update the Makefile
by changing the
EIGEN_LINUX
variable:
To install gcc
and g++
on Ubuntu, run
To install gcc
and g++
on Arch-Linux or
Manjaro, run:
To install gcc
and g++
on Red Hat, Fedor or
CentOS, run:
To install gcc
and g++
on OpenSuse,
run:
Adjusts on Mac
For Mac, especially with intel processors, we found the most stable
compiler to be clang
and clang++
. Thus, one
must have the following lines on the Makefile
:
One should also confirm the location of the Eigen library. The
default location is /usr/local
and is already set at the
Makefile.
If you installed Eigen using Homebrew, you can check the location of the Eigen installation by using the following command:
You can, then, update the EIGEN_MAC
variable in the
Makefile
with the correct path.