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

标签 c++ r profiling rcpp

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

library(RcppArmadillo)
library(Rcpp)

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

sourceCpp('my.cpp')

输出是:

/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.

即使我在 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

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

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

最佳答案

快速的:

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

  2. 我的“HPC with R”幻灯片中有旧的工作示例 talks从几年前开始;这些都应该按原样工作。

关于c++ - 将 Google perftools 指定为 g++ 以便在 R 中使用 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23655492/

相关文章:

javascript - 如何测量函数执行所花费的时间

python - 以编程方式访问 cProfile 数据

javascript - 在 Linux 中分析 Node.JS(代码)执行时间

c++ - 将整数乘以适当分数的快速方法,无需 float 或溢出

c++ - 尝试在 C++ 中读取一行键盘输入

R Shiny 输入 slider 范围值

r - 仅当子字符串是另一个向量的元素时才用逗号分割字符串

c++ - ostringstream 在插入输出后为空

c++ - 复制函数链表c++

r - 50 个州随时间变化的箱线图