我安装了 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。
最佳答案
快速的:
你真的安装了 libgoogle-perftools-dev 包吗?即你有共享库和静态库
/usr/lib/libprofiler.*
吗?这是所有开发常见问题解答之母:您需要打包libfoo
以运行针对 foo 的代码,并打包libfoo-dev
以编译 反对 foo。我的“HPC with R”幻灯片中有旧的工作示例 talks从几年前开始;这些都应该按原样工作。
关于c++ - 将 Google perftools 指定为 g++ 以便在 R 中使用 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23655492/