r - 在 MacOS/CRAN 上构建 R 包时包含 boost tokenizer.hpp 文件时出错

标签 r boost rcpp r-package

由于包含 boost 库时出现特定错误,我在将 R 包发布到 CRAN 时遇到了问题。包中我的一个 .cpp 文件的顶部是

#include <Rcpp.h>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <omp.h>
#include <vector>

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

在 MacOS 上运行检查时(通过 rhub::check(platform = "macos-highsierra-release-cran"),我收到以下错误:

In file included from wgt_jaccard.cpp:6: /Users/user2suimGYX/R/BH/include/boost/tokenizer.hpp:63:9: error: field of type 'std::_1::wrap_iter<const char *>' has private constructor : first(c.begin()), last(c.end()), f(f) { } ^

wgt_jaccard.cpp:117:19: note: in instantiation of function template specialization 'boost::tokenizer<boost::char_separator<char, std::__1::char_traits >, std::__1::__wrap_iter<const char *>, std::__1::basic_string ::tokenizer<Rcpp::internal::string_proxy<16, PreserveStorage> >' requested here tokenizer tokens(y(i), sep); ^

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iterator:1420:31: note: declared private here _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT_DEBUG : __i(__x) {} ^

我的 Makevars 文件的内容是

PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DBOOST_NO_AUTO_PTR
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS)
CXX_STD = CXX11

我尝试四处搜索,但找不到太多关于此错误的信息。完整包位于here 。非常感谢任何帮助。

最佳答案

相对于the repo您好心提供,我们发现需要进行两项更改:

首先,不要(无条件)拥有#include <omp.h>因为 OpenMP 可以是可选的,尤其是。在 macOS 上。简单的#ifdef OPENMP完成这项工作。

其次,(可以说是几乎难以理解的)编译器消息与 tokenizer 的 Boost 类型/类有关。对您通过直接从 Rcpp::CharacterVector 进行索引而提供的 Rcpp 对象感到困惑。已经完成了 - 更保守的方法是首先分配给 std::string然后然后将其传递下去。

通过这两项更改,一切顺利,并且可以在 macOS 上编译 clang++也是如此。

(现已合并,谢谢)PR #2有血淋淋的细节,但很短。

关于r - 在 MacOS/CRAN 上构建 R 包时包含 boost tokenizer.hpp 文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68567416/

相关文章:

r - 如何在 R ( ubuntu ) 中设置代理

r - 如何将向量变成r中的集合

c++ - 一个多索引,其中一个索引是整个集合的一个子集

c++ - operator<< with boost::variant 是如何实现的

c++ - Armadillo 使用的随机数生成器是什么?

r - 在 Rcpp 中快速高效地创建字符 DataFrame

r - 如何处理重叠因子水平? (例如,在制作表格和图表时)

r - 优化 R 中的正则表达式以进行子字符串提取

c++ - 解引用迭代器作为 boost::bind 复合链的一部分

c++ - 在 RcppArmadillo 中使用字段