title: How to specify (non-R) library path for dynamic library loading in R?
body: <p>I keep getting the following error when attempting to install <code>readxl</code> or <code>haven</code> in R (both dependencies of <code>tidyverse</code>) post-compilation, when the installer runs the loading test:</p>
  
  <pre><code>** testing if installed package can be loaded
  Error in dyn.load(file, DLLpath = DLLpath, ...) :
    unable to load shared object '&lt;my_lib_Path&gt;/readxl/libs/readxl.so':
    &lt;my_lib_path&gt;/readxl/libs/readxl.so: undefined symbol: libiconv
  Error loading failed
  </code></pre>
  
  <p>I have <code>libiconv.so</code> in a local lib path (not for R packages) that is included in <code>LD_LIBRARY_PATH</code> and I've verified in my R session that <code>Sys.getenv("LD_LIBRARY_PATH")</code> has that directory.
  Why can't R's dynamic library loader find this shared object?  <strong>Is there a different R-specific environment variable I need to define to have the dynamic library loader in R search my local lib path?</strong></p>
  
  <p>Please note that this is not an issue with an R library path, but instead for a non-R dependency that an R package has.  If I were compiling and linking C++ code, <code>gcc</code> would use <code>ld</code>, and hence <code>LD_LIBRARY_PATH</code> to track down dynamic dependencies.  R doesn't appear to respect this rather common approach, and I can't seem to find any documentation on how to manage these more fine-grained dependency issues.</p>
  
  <hr>
  
  <h2>Additional Details</h2>
  
  <pre><code>!&gt; sessionInfo()
   R version 3.3.3 (2017-03-06)
   Platform: x86_64-pc-linux-gnu (64-bit)
   Running under: CentOS Linux 7 (Core)
  
   locale:
    [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
    [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
    [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
    [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
    [9] LC_ADDRESS=C               LC_TELEPHONE=C
   [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
  
   attached base packages:
   [1] stats     graphics  grDevices utils     datasets  methods   base
   &gt; 
  </code></pre>
  
  <p>I had previously compiled <code>libiconv</code> because it was a dependency for something else (don't recall what now - likely not an R package given current problems).  I tried reinstalling it, but made no difference.</p>
  
  <hr>
  
  <h3>Edit</h3>
  
  <p>I have also tried manually loading the library prior to installation:</p>
  
  <pre><code>&gt; dyn.load(".local/lib/libiconv.so")
  &gt; is.loaded("libiconv")
  [1] TRUE
  &gt; install.packages("tidyverse")
  </code></pre>
  
  <p>but it fails just as above.</p>