使用带有Rcpp的boost / regex

时间:2014-05-09 03:39:23

标签: r boost rcpp

我正在尝试在R中编译基于boost / regrex的库函数。这是我的示例代码:

// [[Rcpp::depends(BH)]]
#include <Rcpp.h>
#include <boost/regex.hpp>

using namespace Rcpp;  
using namespace boost;
using namespace std;

string jphtest(string);

// [[Rcpp::export]]
string jphtest(string src) {

        return(regex_replace(src, regex("ABC"), "123"));
}

当我尝试使用R CMD检查进行测试时,它不起作用。这是我得到的错误:

** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/Users/howardjp/Documents/Research/foniks/..Rcheck/foniks/libs/foniks.so':   
dlopen(/Users/howardjp/Documents/Research/foniks/..Rcheck/foniks/libs/foniks.so, 6): Symbol not found: __ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9do_assignEPKcS7_j
  Referenced from: /Users/howardjp/Documents/Research/foniks/..Rcheck/foniks/libs/foniks.so
  Expected in: flat namespace in /Users/howardjp/Documents/Research/foniks/..Rcheck/foniks/libs/foniks.so
Error: loading failed
Execution halted

有关如何纠正此问题的任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:2)

BH软件包非常方便将Boost的很大一部分打包在一个只有标头的库中,您可以通过LinkingTo:或我们的插件在R中使用它。

但是,还有一部分Boost需要链接,而regex就是其中之一。文件系统,线程,program_options,......是其他示例。您可以在包中或通过显式链接指令执行此操作,就像我在Gabor已经指出的Rcpp Gallery article中所做的那样。请注意,该解决方案并非完全可移植;你需要一个包来链接到Windows,OS X,Linux等上的正确文件扩展名。

简而言之,您对Gabor评论的驳回是错误的,因为您似乎忽略了Boost Regex不仅仅是标题。

相关问题