我正在嘗試使用inline
庫。內聯函數代碼不能編譯
我試圖給出的第一個例子,在http://adv-r.had.co.nz/C-interface.html
library(inline)
add <- cfunction(signature(a = "integer", b = "integer"), "
SEXP result;
PROTECT(result = allocVector(REALSXP, 1));
REAL(result)[0] = asReal(a) + asReal(b);
UNPROTECT(1);
return(result);
")
我得到以下錯誤:
Warning message:
running command 'make -f "C:/PROGRA~1/R/R-30~1.3/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-30~1.3/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="file21e05c17451a.dll" WIN=64 TCLBIN=64 OBJECTS="file21e05c17451a.o"' had status 127
ERROR(s) during compilation: source code errors or compiler configuration errors!
Program source:
1: #include <R.h>
2: #include <Rdefines.h>
3: #include <R_ext/Error.h>
4:
5:
6: extern "C" {
7: SEXP file21e05c17451a (SEXP a, SEXP b);
8: }
9:
10: SEXP file21e05c17451a (SEXP a, SEXP b) {
11:
12: SEXP result;
13:
14: PROTECT(result = allocVector(REALSXP, 1));
15: REAL(result)[0] = asReal(a) + asReal(b);
16: UNPROTECT(1);
17:
18: return(result);
19:
20: warning("your C program does not return anything!");
21: return R_NilValue;
22: }
Error in compileCode(f, code, language, verbose) :
Compilation ERROR, function(s)/method(s) not created! Warning message:
running command 'make -f "C:/PROGRA~1/R/R-30~1.3/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-30~1.3/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="file21e05c17451a.dll" WIN=64 TCLBIN=64 OBJECTS="file21e05c17451a.o"' had status 127
In addition: Warning message:
running command 'C:/PROGRA~1/R/R-30~1.3/bin/x64/R CMD SHLIB file21e05c17451a.cpp 2> file21e05c17451a.cpp.err.txt' had status 1
我試圖evalCpp("2+2")
從Rcpp
包,它給了我4
的答案。所以,我想編譯器本身沒有任何問題。這裏可能是什麼問題?
我運行Windows 7.我sessionInfo
如下:
R version 3.0.3 (2014-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] compiler stats graphics grDevices utils datasets methods base
other attached packages:
[1] inline_0.3.13 stringr_0.6.2 rhdf5_2.6.0
[4] RcppRoll_0.1.0 RcppArmadillo_0.4.200.0 Rcpp_0.11.1
[7] data.table_1.9.2
loaded via a namespace (and not attached):
[1] plyr_1.8.1 reshape2_1.2.2 tools_3.0.3 zlibbioc_1.8.0
*編輯*
試圖在那裏R
安裝在一個目錄沒有任何空間與Windows 7的另一臺電腦上並且最近安裝了R 3.1.0
。所以這絕對不是由於R
路徑有空格。
*編輯*
我終於得到這個工作!需要將Rtools
目錄添加到PATH
。
我得到了完全相同的錯誤,在我的Windows 7機器上,但不是在一個運行debian。 – Stedy