当我在R中使用Rcpp时,包含boost的编译错误

时间:2018-08-14 06:23:38

标签: r boost rcpp

尽管我已经有了RTools和BH软件包,但还是出现了以下错误。 (我使用的是Win10 64位和R 3.5.1)

当我编译其他软件包时,Rtools效果很好。

我已经看过许多相关的问答,但无法解决。

请帮助这个新手。

> sourceCpp('D:/Data/Drive/RCodes/scRNA-seq/TransSyn/TransSyn.cpp')
c:/Rtools/mingw_64/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-35~1.1/include" - 
DNDEBUG   -I"C:/Users/CEO/Documents/R/win-library/3.5/Rcpp/include" - 
I"D:/Data/Drive/RCodes/scRNA-seq/TransSyn"        -O2 -Wall  -mtune=generic -c 
TransSyn.cpp -o TransSyn.o
TransSyn.cpp:5:37: fatal error: boost/functional/hash.hpp: No such file or 
directory
 #include <boost/functional/hash.hpp>
                                 ^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-35~1.1/etc/x64/Makeconf:215: TransSyn.o] Error 1
Error in sourceCpp("D:/Data/Drive/RCodes/scRNA-seq/TransSyn/TransSyn.cpp") : 
  Error 1 occurred building shared library.
WARNING: Rtools is required to build R packages but is not currently installed. 
Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/

1 个答案:

答案 0 :(得分:2)

通过编译命令,我们可以了解到您没有包括boost包中的BH标头:

c:/Rtools/mingw_64/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-35~1.1/include"
 -DNDEBUG   -I"C:/Users/CEO/Documents/R/win-library/3.5/Rcpp/include" 
 -I"D:/Data/Drive/RCodes/scRNA-seq/TransSyn"        -O2 -Wall  -mtune=generic -c
 TransSyn.cpp -o TransSyn.o

缺少-I"C:/Users/CEO/Documents/R/win-library/3.5/BH/include"。您可以通过添加

来解决此问题
// [[Rcpp::depends(BH)]]

D:/Data/Drive/RCodes/scRNA-seq/TransSyn/TransSyn.cpp。当然,您必须确保安装了BH