繁体   English   中英

在通过RcppGSL使用Gnu科学库编译cpp代码wihtin R时,包含某些GSL头文件会产生错误

[英]When compiling cpp-code wihtin R making use of the Gnu Scientific Library via RcppGSL, inclusion of some GSL-header files produce errors

使用RcppGSL包在R中编译c ++代码时遇到问题。 我在Unix上(Ubuntu 13.10,安装在Oracle VM VirtualBox中; R版本3.0.2)。 我设法利用GSL库安装了所有代码汇编所需的东西(至少我是这样认为的)。 以下代码没问题:

library(RcppGSL)
library(inline)

code <- ' 
#include<gsl/gsl_vector.h>
//#include<gsl/gsl_pow_int.h>

RcppGSL::vector<double> v(1);
v[0] = 1.23;
double ret = v[0];
v.free() ;
return(Rcpp::wrap(ret));
' 
foo <- cxxfunction(signature(), code, plugin = "RcppGSL", verbose = T)

这样可以很好地编译,该函数按预期返回1.23。 但是,一旦我包含gsl_vector.h或gsl_matrix.h之外的其他头文件(例如在上例中,当gsl / gsl_pow_int.h在第6行未注释掉时),我得到以下错误消息:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from file196520f2906c.cpp:32:0:
/usr/include/gsl/gsl_pow_int.h: In function ‘SEXPREC* file196520f2906c()’:
/usr/include/gsl/gsl_pow_int.h:34:1: error: expected unqualified-id before string constant
 __BEGIN_DECLS
 ^
make: *** [file196520f2906c.o] Error 1

我不知道这是怎么回事。 任何帮助表示赞赏。

谢谢

我想您这里只是一些基本错误。 以下变体可以正常工作:

#include<RcppGSL.h>
#include<gsl/gsl_vector.h>
#include<gsl/gsl_pow_int.h>

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

// [[Rcpp::export]]
double foo(int ignored) {
    RcppGSL::vector<double> v(1);
    v[0] = 1.23;
    double ret = v[0];
    v.free() ;
    return ret;
}

根据快速测试:

R> sourceCpp("/tmp/so2.cpp")
R> foo(3)
[1] 1.23
R> 

有示例:RcppGSL程序包本身包含一个简单但完整的程序包(使用矢量规范); 在Rcpp画廊上也有帖子。

通常来说,包括我们的头文件RcppGSL.h已经为向量和矩阵RcppGSL.h了GSL头文件,因此,如果再次包含它们(我们的示例都没有),则可能确实会出错-必须有一定的顺序使模板魔术工作。

暂无
暂无

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

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