Rcpp Compilation ERROR: 'clang: error: no such file or directory: '/usr/local/lib/libfontconfig.a'
<p>I was trying to run this peace of code in R (credit to <a href="http://brainchronicle.blogspot.co.uk/2012/06/rcpp-vs-r-implementation-of-cosine.html" rel="nofollow noreferrer">the author</a>):</p>

<pre><code>require(Rcpp)
require(RcppArmadillo)
require(inline)
cosineRcpp &lt;- cxxfunction( 
  signature(Xs = "matrix"), 
  plugin = c("RcppArmadillo"),
  body='
    Rcpp::NumericMatrix Xr(Xs);  // creates Rcpp matrix from SEXP
    int n = Xr.nrow(), k = Xr.ncol();
    arma::mat X(Xr.begin(), n, k, false); // reuses memory and avoids extra copy
    arma::mat Y = arma::trans(X) * X; // matrix product
    arma::mat res = (1 - Y / (arma::sqrt(arma::diagvec(Y)) * arma::trans(arma::sqrt(arma::diagvec(Y)))));
    return Rcpp::wrap(res);
')
</code></pre>

<p>And got, after few fixes, the following error:</p>

<pre><code>Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! 
clang: error: no such file or directory: '/usr/local/lib/libfontconfig.a'
clang: error: no such file or directory: '/usr/local/lib/libreadline.a'
make: *** [file5a681e35ebe1.so] Error 1
In addition: Warning message:
running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file5a681e35ebe1.cpp 2&gt; file5a681e35ebe1.cpp.err.txt' had status 1 
</code></pre>

<p>I used to use Rcpp a lot in the past. But between now and then my computer has been reformatted and all the installation re-done using homebrew.</p>

<p>I installed <code>cairo</code> with brew: <code>brew install cairo</code></p>

<p>the <code>libreadline.a</code> error was solved with:</p>

<pre><code>brew link --force readline
</code></pre>

<p>But the same did not work for <code>libfontconfig.a</code> since was already linked:</p>

<pre><code>brew link --force fontconfig
Warning: Already linked: /usr/local/Cellar/fontconfig/2.11.1
To relink: brew unlink fontconfig &amp;&amp; brew link fontconfig
</code></pre>

<p>I would have assumed that <code>fontconfig</code> is within <code>cairo</code>. In fact, when I type </p>

<pre><code>brew install fontconfig
Warning: fontconfig-2.11.1 already installed
</code></pre>

<p>But the truth is that there is no <code>libfontconfig.a</code> at <code>/usr/local/lib/</code>:</p>

<pre><code>ls /usr/local/lib/libfont*
/usr/local/lib/libfontconfig.1.dylib 
/usr/local/lib/libfontconfig.dylib
</code></pre>

<p>Using the very questionable approach of going <a href="http://www.filewatcher.com/m/libfontconfig.a.434524-0.html" rel="nofollow noreferrer">here</a> and download it, the code runs, but still gives a the corresponding warning, since the file corresponds to a different os.x architecture (I did not found one for 10.9): </p>

<pre><code>+ . + ld: warning: ignoring file /usr/local/lib/libfontconfig.a, missing required architecture x86_64 in file /usr/local/lib/libfontconfig.a (2 slices)
</code></pre>

<p>So at this stage I am a little lost. </p>

<p>How do I install <code>libfontconfig.a</code> or find the 10.9 version?</p>

<p>In case is of any use, I have Xcode installed, I am on a Mac 10.9.5, 
and based on <a href="https://stackoverflow.com/questions/29992066/rcpp-warning-directory-not-found-for-option-l-usr-local-cellar-gfortran-4-8">this</a> very nice and detailed answer my <code>~/.R/Makevars</code> file looks like:</p>

<pre><code>CC=clang
CXX=clang++
FLIBS=-L/usr/local/bin/
</code></pre>