将Google perftools指定为g ++以在R中使用C++

Tim*_*Tim 1 c++ profiling r rcpp

我在编译C++代码时安装了Google perftools(google-perftools 1.7-1ubuntu1),并将-lprofiler添加到R中的PKG_LIBS.

library(RcppArmadillo)
library(Rcpp)

Sys.setenv("PKG_CXXFLAGS"="-fopenmp")
Sys.setenv("PKG_LIBS"="-fopenmp -lprofiler")

sourceCpp('my.cpp')
Run Code Online (Sandbox Code Playgroud)

输出是:

/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.
Run Code Online (Sandbox Code Playgroud)

即使我在bash中运行g ++,我也会遇到同样的错误

$ 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
Run Code Online (Sandbox Code Playgroud)

我想知道为什么-lprofiler不指定谷歌perfotools?我该如何解决这个问题?谢谢!

我的g ++是g ++(Ubuntu/Linaro 4.6.3-1ubuntu5)4.6.3.

Dir*_*tel 6

快速的:

  1. 你真的安装了包libgoogle-perftools-dev吗?即你有共享和静态库/usr/lib/libprofiler.*吗?这是所有开发常见问题解答的母亲:你需要打包libfoo来针对foo 运行代码,并打包libfoo-dev以针对foo 进行编译.

  2. 几年前,我在'HPC with R' 演讲的幻灯片中有旧的工作实例; 那些都应该按原样运作.