A.12 从源码安装 R

从源码编译 R 的需求大概有以下几点:

  1. 爱折腾的极客:玩配置,学习 make 相关工具和 Linux 世界的依赖
  2. 追求性能:如 LFS 支持Intel MKL 加速
  3. 环境限制:CentOS 或者红帽系统,自带的 R 版本比较落后
./configure --prefix=/opt/R/R-devel \
  --enable-R-shlib --enable-byte-compiled-packages \
  --enable-BLAS-shlib --enable-memory-profiling --with-blas="-lopenblas"
R is now configured for x86_64-pc-linux-gnu

  Source directory:            .
  Installation directory:      /opt/R/R-devel

  C compiler:                  gcc  -g -O2
  Fortran fixed-form compiler: gfortran -fno-optimize-sibling-calls -g -O2

  Default C++ compiler:        g++ -std=gnu++11  -g -O2
  C++14 compiler:              g++ -std=gnu++14  -g -O2
  C++17 compiler:              g++ -std=gnu++17  -g -O2
  C++20 compiler:              g++ -std=gnu++2a  -g -O2
  Fortran free-form compiler:  gfortran -fno-optimize-sibling-calls -g -O2
  Obj-C compiler:               

  Interfaces supported:        X11, tcltk
  External libraries:          pcre2, readline, BLAS(OpenBLAS), curl
  Additional capabilities:     PNG, JPEG, TIFF, NLS, cairo, ICU
  Options enabled:             shared R library, shared BLAS, R profiling, memory profiling

  Capabilities skipped:        
  Options not enabled:         

  Recommended packages:        yes

配置好了以后,可以编译安装了

make && sudo make install

flexiblas 支持多种 BLAS 库自由切换