我正在尝试使用sourceCpp和RcppArmadillo来编译一些c ++代码。我在Ubuntu,Rcpp 0.12.10和RcppArmadillo 0.7.800.2.0上使用R 3.3.3。文件armatest.cpp完全被删除了。
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
using namespace arma;
using namespace Rcpp;
int one() {
return 1;
}
当我尝试从Rstudio服务器中编译它时,我收到以下编译错误:
> Rcpp::sourceCpp("armatest.cpp", verbose = TRUE, rebuild=TRUE)
Generated extern "C" functions
--------------------------------------------------------
#include <Rcpp.h>
Generated R functions
-------------------------------------------------------
`.sourceCpp_1_DLLInfo` <- dyn.load('/tmp/Rtmp3oSZra/sourceCpp-x86_64-pc-linux-gnu-0.12.10/sourcecpp_47d41ae4918/sourceCpp_10.so')
rm(`.sourceCpp_1_DLLInfo`)
Building shared library
--------------------------------------------------------
DIR: /tmp/Rtmp3oSZra/sourceCpp-x86_64-pc-linux-gnu-0.12.10/sourcecpp_47d41ae4918
/usr/lib/R/bin/R CMD SHLIB -o 'sourceCpp_10.so' --preclean 'armatest.cpp'
g++ -I/usr/share/R/include -DNDEBUG -I"/home/amercer/R/x86_64-pc-linux-gnu-library/3.3/Rcpp/include" -I"/home/amercer/R/x86_64-pc-linux-gnu-library/3.3/RcppArmadillo/include" -I"/home/amercer" -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c armatest.cpp -o armatest.o
g++ -shared -L/usr/lib/R/lib -Wl,-z,relro -o sourceCpp_10.so armatest.o -llapack -lblas -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lR
/usr/share/R/share/make/shlib.mk:6: recipe for target 'sourceCpp_10.so' failed
Error in Rcpp::sourceCpp("armatest.cpp", verbose = TRUE, rebuild = TRUE) :
Error 1 occurred building shared library.
但是,当我从命令行(Rstudio-server之外)运行R,然后重试时,它编译得很好。
>Rcpp::sourceCpp("armatest.cpp", verbose = TRUE, rebuild=TRUE)
Generated extern "C" functions
--------------------------------------------------------
#include <Rcpp.h>
Generated R functions
-------------------------------------------------------
`.sourceCpp_1_DLLInfo` <- dyn.load('/tmp/RtmptRileh/sourceCpp-x86_64-pc-linux-gnu-0.12.10/sourcecpp_1966315b9edd0/sourceCpp_4.so')
rm(`.sourceCpp_1_DLLInfo`)
Building shared library
--------------------------------------------------------
DIR: /tmp/RtmptRileh/sourceCpp-x86_64-pc-linux-gnu-0.12.10/sourcecpp_1966315b9edd0
/usr/lib/R/bin/R CMD SHLIB -o 'sourceCpp_4.so' --preclean 'armatest.cpp'
g++ -I/usr/share/R/include -DNDEBUG -I"/home/amercer/R/x86_64-pc-linux-gnu-library/3.3/Rcpp/include" -I"/home/amercer/R/x86_64-pc-linux-gnu-library/3.3/RcppArmadillo/include" -I"/home/amercer" -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c armatest.cpp -o armatest.o
g++ -shared -L/usr/lib/R/lib -Wl,-z,relro -o sourceCpp_4.so armatest.o -llapack -lblas -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lR
Warning message:
In Rcpp::sourceCpp("armatest.cpp", verbose = TRUE, rebuild = TRUE) :
No Rcpp::export attributes or RCPP_MODULE declarations found in source
据我所知,他们使用相同的标志执行完全相同的命令。是什么解释了差异?在Rstudio服务器上,Rcpp本身对我来说很合适,所以它特别关注RcppAarmadillo。
答案 0 :(得分:0)
可能是你的设置本地的东西,因为它在RStudio也很好用但是请注意我添加了<script type="text/javascript">
function getValues() {
var response = <%GetCharges%>
document.getElementById(("<%=txtcharge.ClientID%>")).value = response;}
} </script>
以及一个自动执行的例子:
// [[Rcpp::export]]
你的例子,最低限度改变:
> Rcpp::sourceCpp("/tmp/armaQ.cpp")
> one()
[1] 1
>