title: Why can R be linked to a shared BLAS later even if it was built with `--with-blas = lblas`?
body: <p>The <a href="https://cran.r-project.org/doc/manuals/r-release/R-admin.html#BLAS" rel="noreferrer">BLAS section in R installation and administration manual</a> says that when R is built <strong>from source</strong>, with configuration parameter <code>--without-blas</code>, it will build Netlib's reference BLAS into a standalone shared library at <code>R_HOME/lib/libRblas.so</code>, along side the standard R shared library <code>R_HOME/lib/libR.so</code>. This makes it easier for user to switch and benchmark different tuned BLAS in R environment. The guide suggests that researcher might use symbolic link to <code>libRblas.so</code> to achieve this, and <a href="http://www.rochester.edu/college/psc/thestarlab/help/moreclus/BLAS.pdf" rel="noreferrer">this article</a> gives more details on this.</p>
  
  <p>On contrary, when simply installing a pre-compiled binary version of R, either from R CRAN's mirrors or Ubuntu's repository (for linux user like me), <strong>in theory</strong> it should be more difficult to switch between different BLAS without rebuilding R, because a pre-compiled R version is configured with <code>--with-blas = (some blas library)</code>. We can easily check this, either by reading configuration file at <code>R_HOME/etc/Makeconf</code>, or check the result of <code>R CMD config BLAS_LIBS</code>. For example, on my machine it returns <code>-lblas</code>, so it is linked to reference BLAS <strong>at build time</strong>. As a result, there is no <code>R_HOME/lib/libRblas.so</code>, only <code>R_HOME/lib/libR.so</code>.</p>
  
  <p>However, <a href="http://edustatistics.org/nathanvan/2013/07/09/for-faster-r-use-openblas-instead-better-than-atlas-trivial-to-switch-to-on-ubuntu/" rel="noreferrer">this R-blog</a> says that it is possible to switch between difference BLAS, even if R is not installed from source. The author tried the ATLAS and OpenBLAS from ubuntu's repository, and then use <code>update-alternatives --config</code> to work around. It is also possible to configure and install tuned BLAS from source, add them to "alternatives" through <code>update-alternatives --install</code>, and later switch between them in the same way. The BLAS library (a symbolic link) in this case will be found at <code>/usr/lib/libblas.so.3</code>, which is under both ubuntu and R's <code>LD_LIBRARY_PATH</code>. I have tested and this does work! <strong>But I am very surprised at how R achieves this.</strong>  As I said, R should have been tied to the BLAS library configured at building time, i.e., I would expect all BLAS routines integrated into <code>R_HOME/lib/libR.so</code>. So why is it still possible to change BLAS via <code>/usr/lib/libblas.so.3</code>?</p>
  
  <p>Thanks if someone can please explain this.</p>