将 Google perftools 指定为 g++ 以在 R 中使用 C++ [英] Specifying Google perftools to g++ for using C++ in R

查看:45
本文介绍了将 Google perftools 指定为 g++ 以在 R 中使用 C++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I installed Google perftools (google-perftools 1.7-1ubuntu1), and add -lprofiler to PKG_LIBS in R, when compiling the C++ code.

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++,我也会得到同样的错误

Even if I run g++ in bash, I get the same error

$ 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?我该如何解决问题?谢谢!

I wonder why -lprofiler doesn't specify google perfotools? How can I solve the problem? Thanks!

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

My g++ is g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3.

推荐答案

快速解决方案:

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

  1. Do you actually have the package libgoogle-perftools-dev installed? Ie do you have shared and static libraries /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.

我的HPC with R"幻灯片中有旧的工作示例谈话 从几年前开始;这些都应该按原样工作.

I have old working examples in the slides from my 'HPC with R' talks from a few years ago; those should all work as is.

这篇关于将 Google perftools 指定为 g++ 以在 R 中使用 C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆