由于包含 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/