title: Specifying Google perftools to g++ for using C++ in R
body: <p>I installed Google perftools (google-perftools 1.7-1ubuntu1), and add -lprofiler to PKG_LIBS in R, when compiling the C++ code.</p>
  
  <pre><code>library(RcppArmadillo)
  library(Rcpp)
  
  Sys.setenv("PKG_CXXFLAGS"="-fopenmp")
  Sys.setenv("PKG_LIBS"="-fopenmp -lprofiler")
  
  sourceCpp('my.cpp')
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>/usr/bin/ld: cannot find -lprofiler
  collect2: ld returned 1 exit status
  make: *** [sourceCpp_17496.so] Error 1
  g++ -I/usr/share/R/include -DNDEBUG    -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include"   -fopenmp -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c my.cpp -o my.o g++ -shared -Wl,-Bsymbolic-functions -Wl,-z,relro -o sourceCpp_17496.so my.o -llapack -lblas -lgfortran -lm -lquadmath -fopenmp -fopenmp -lprofiler -L/usr/lib/R/lib -lR 
  Error in sourceCpp("my.cpp") : 
    Error 1 occurred building shared library.
  
  WARNING: The tools required to build C++ code for R were not found.
  
  Please install GNU development tools including a C++ compiler.
  </code></pre>
  
  <p>Even if I run g++ in bash, I get the same error</p>
  
  <pre><code>$ g++ -shared -Wl,-Bsymbolic-functions -Wl,-z,relro -o sourceCpp_17496.so my.o -llapack -lblas -lgfortran -lm -lquadmath -fopenmp -fopenmp -lprofiler -L/usr/lib/R/lib -lR 
  /usr/bin/ld: cannot find -lprofiler
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>I wonder why <code>-lprofiler</code> doesn't specify google perfotools? How can I solve the problem? Thanks!</p>
  
  <p>My g++ is g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3.</p>