简体   繁体   English

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

[英]Specifying Google perftools to g++ for using C++ in R

I installed Google perftools (google-perftools 1.7-1ubuntu1), and add -lprofiler to PKG_LIBS in R, when compiling the C++ code. 我安装了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')

The output is: 输出为:

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

Even if I run g++ in bash, I get the same error 即使我在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

I wonder why -lprofiler doesn't specify google perfotools? 我想知道为什么-lprofiler不指定google perfotools? How can I solve the problem? 我该如何解决这个问题? Thanks! 谢谢!

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

Quick ones: 快速的:

  1. Do you actually have the package libgoogle-perftools-dev installed? 您是否实际安装了libgoogle-perftools-dev软件包? Ie do you have shared and static libraries /usr/lib/libprofiler.* ? 即,您是否具有共享库和静态库/usr/lib/libprofiler.* This is the mother of all development FAQs: you need package libfoo to run code against foo, and package libfoo-dev to compile against foo. 这是所有开发常见问题的libfoo :您需要libfoo软件包libfoo对foo 运行代码,并且需要libfoo-dev软件包来对foo进行编译

  2. I have old working examples in the slides from my 'HPC with R' talks from a few years ago; 几年前的“带R的HPC” 演讲的幻灯片中,我有一些古老的工作示例。 those should all work as is. 这些都应该按原样工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM