如何++使用Boost库用C与RCPP [英] How to use Boost library in C++ with Rcpp

查看:177
本文介绍了如何++使用Boost库用C与RCPP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的 RCPP 研究3.0.0 包。我试图运行 这个例子 ,但我不能,因为我不知道如何使用加速

I am using Rcpp package on R 3.0.0. I am trying to run this example, but I cannot because I don't know how to use Boost.

我在目录/用户/ GIORGI / boost_1_53_0安装升压所以我设置 Sys.setenv(PKG_CXXFLAGS= - I /用户/ GIORGI / boost_1_53_0)但我不知道我在做正确的事情。很抱歉,但我对这个东西很无知!

I installed Boost in the directory /Users/giorgi/boost_1_53_0 therefore I set Sys.setenv("PKG_CXXFLAGS"="-I /Users/giorgi/boost_1_53_0") but I am not sure I am doing the right thing. Sorry but I am quite ignorant with this stuff!

推荐答案

我会尝试一些事情:


  1. 编写使用Boost三线独立的C ++程序,并进行编译。这仅仅是为了证明自己,你有 -I /一些/ DIR 标志对的。

编写一个简单的RCPP功能,并使用如 sourceCpp()编译并加载它。

Write a simple Rcpp function and use eg sourceCpp() to compile and load it.

创建一个文件〜/ .R / Makevars ,并从1设置 -I 标记。这里的任何一个 CXXFLAGS CFLAGS 两者之一将研究CMD使用... ,因此 sourceCpp()

Create a file ~/.R/Makevars and set the -I flag from 1. here as either one one of CXXFLAGS or CFLAGS both of which will be used by R CMD ... and hence sourceCpp().

如果一切都失败了,创建一个小包装,并添加 LinkingTo:BH 作为CRAN包BH提供升压你可以使用头文件(一旦你安装BH) 。

If everything else fails, create a small package and add LinkingTo: BH as the CRAN package BH provides Boost headers you can use (once you install BH).

编辑,约1 1/2年后

您也可以使用 // [RCPP ::取决于(BH)] 作为例如,在此code

You can also use a // [[Rcpp::depends(BH)]] as eg in this code

#include <Rcpp.h>
#include <boost/math/common_factor.hpp>  // included in BH  

// [[Rcpp::depends(BH)]]    

using namespace Rcpp;

// [[Rcpp::export]]   
int computeGCD(int a, int b) {
  return boost::math::gcd(a, b);
}

建造了和我们在此期间更新都RCPP和BH运行良好:

which builds and runs just fine as we updated both Rcpp and BH in the meantime:

R> library(Rcpp)
R> sourceCpp("/tmp/simpleBoost.cpp")
R> computeGCD(6, 15)
[1] 3
R> 

这篇关于如何++使用Boost库用C与RCPP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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