我在R软件包项目中有一个名为src/windows.cpp
的文件(向量的窗口函数,与MS Windows无关!)。文件顶部如下所示:
// [[Rcpp::depends(BH)]]
// [[Rcpp::plugins(cpp11)]]
#include <Rcpp.h>
#include <algorithm>
#include <boost/algorithm/string/join.hpp>
using namespace Rcpp;
这似乎不足以让它找到Boost标头 - 当我执行devtools::load_all(.)
来触发编译时,我看到这个构建失败:
* installing *source* package ‘MyPackage’ ...
** libs
g++ -m64 -I/usr/include/R -DNDEBUG -I"/home/rstudio/R/x86_64-redhat-linux-gnu-library/3.4/Rcpp/include"
-I/usr/local/include -std=c++11 -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2
-fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -c windows.cpp -o windows.o
windows.cpp:6:43: fatal error: boost/algorithm/string/join.hpp: No such file or directory
#include <boost/algorithm/string/join.hpp>
^
compilation terminated.
我已安装BH
,并且存在相关标头:
> .libPaths()[1]
[1] "/home/rstudio/R/x86_64-redhat-linux-gnu-library/3.4"
> dir(file.path(.libPaths()[1], 'BH/include/boost/algorithm/string'))
[1] "case_conv.hpp" "classification.hpp" "compare.hpp"
[4] "concept.hpp" "config.hpp" "constants.hpp"
[7] "detail" "erase.hpp" "find_format.hpp"
[10] "find_iterator.hpp" "find.hpp" "finder.hpp"
[13] "formatter.hpp" "iter_find.hpp" "join.hpp"
[16] "predicate_facade.hpp" "predicate.hpp" "regex_find_format.hpp"
[19] "regex.hpp" "replace.hpp" "sequence_traits.hpp"
[22] "split.hpp" "std" "std_containers_traits.hpp"
[25] "trim_all.hpp" "trim.hpp" "yes_no_type.hpp"
看起来核心问题是[[Rcpp::depends(BH)]]
指令没有将相关的Boost目录添加到编译器指令中,对吧?在我的设置中我应该寻找什么可能导致这种情况?
我已将BH
添加到Imports:
文件的DESCRIPTION
部分,这是正确/可取的吗?