我正在关注'Writing R extensions manual'版本3.3.1中的示例。具体来说,我正在使用c ++代码,我已将其保存在文件out.cpp中,该文件位于该手册的第115页,如下所示:
after_destroy
我有一台Windows计算机并使用cygwin命令行。在那里我输入了R CMD SHLIB out.cpp并得到以下结果:
>>> l = ['Gerber, Len', 'Fox, Kate', 'Dunn, Bob']
>>> print [[x.split(',')[1].strip() for x in l], [x.split(',')[0].strip() for x in l]]
[['Len', 'Kate', 'Bob'], ['Gerber', 'Fox', 'Dunn']]
我认为这没有错,对吧?然后当我进入Rstudio我输入
#include <R.h>
#include <Rinternals.h>
SEXP out(SEXP x, SEXP y)
{
int nx = length(x), ny = length(y);
SEXP ans = PROTECT(allocMatrix(REALSXP, nx, ny));
double *rx = REAL(x), *ry = REAL(y), *rans = REAL(ans);
for(int i = 0; i < nx; i++) {
double tmp = rx[i];
for(int j = 0; j < ny; j++)
rans[i + nx*j] = tmp * ry[j];
}
UNPROTECT(1);
return ans;
}
它没有给我任何错误信息。但是当我跑步时
cygwin warning:
MS-DOS style path detected: C:/R-3.2.3/etc/x64/Makeconf
Preferred POSIX equivalent is: /cygdrive/c/R-3.2.3/etc/x64/Makeconf
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
g++ -m64 -I"C:/R-3.2.3/include" -DNDEBUG -I"d:/RCompile/r- compiling/local/local323/include" -O2 -Wall -mtune=core2 -c out.cpp -o out.o
g++ -m64 -shared -s -static-libgcc -o out.dll tmp.def out.o -Ld:/RCompile/r-compiling/local/local323/lib/x64 -Ld:/RCompile/r-compiling/local/local323/lib -LC:/R-3.2.3/bin/x64 -lR
我得到'FALSE',所以我永远无法上传out.dll。你能帮我解决这个问题吗?
P.S。:我知道如何使用Rcpp运行这样的函数,所以请不要告诉我这样做。我想要做的是非常理解Writing Extensions手册,所以我希望我能够完成该文档中的所有示例。
谢谢。