Reputation: 23975
I have a file called src/windows.cpp
(windowing functions for vectors, nothing to do with MS Windows!) in an R package project. The top of the file looks like this:
// [[Rcpp::depends(BH)]]
// [[Rcpp::plugins(cpp11)]]
#include <Rcpp.h>
#include <algorithm>
#include <boost/algorithm/string/join.hpp>
using namespace Rcpp;
That doesn't seem to be enough to let it find the Boost headers - when I do a devtools::load_all(.)
to trigger compilation, I see this build failure:
* 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.
I've got BH
installed, and the relevant headers are present:
> .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"
It looks like the core problem is that the [[Rcpp::depends(BH)]]
directive isn't adding the relevant Boost directory to the compiler directives, right? What should I look for in my setup that might be causing this?
I've added BH
to the Imports:
section of my DESCRIPTION
file, is that correct/advisable?
Upvotes: 3
Views: 903
Reputation: 4841
Have you added it to LinkingTo
as mentioned here?
Note that while the
Rcpp::depends
attribute establishes dependencies forsourceCpp
, it’s important to note that if you include the same source file in an R package these dependencies must still be listed in theImports
and/orLinkingTo
fields of the packageDESCRIPTION
file. ... Packages that provide only C++ header files (and no shared library) need only be referred to usingLinkingTo
.
Upvotes: 4