内联函数代码无法编译 [英] inline function code doesn't compile

查看:25
本文介绍了内联函数代码无法编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 inline 库.

I am trying to experiment with the inline library.

我尝试了 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  

我尝试了 Rcpp 包中的 evalCpp("2+2"),它给了我 4 作为答案.所以,我想编译器本身没有任何问题.这可能是什么问题?

I tried evalCpp("2+2") from the Rcpp package and it gave me 4 as the answer. So, I guess there isn't anything wrong with the compiler per se. What could be the issue here?

我运行的是 Windows 7.我的 sessionInfo 如下:

I'm running Windows 7. My sessionInfo is as follows:

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

* 编辑 *

在另一台装有 Windows 7 的 PC 上尝试过,其中 R 安装在没有任何空格的目录中,并且最近安装了 R 3.1.0.所以这绝对不是因为 R 路径有空格.

Tried on another PC with Windows 7 where R is installed in a directory without any spaces and recently had R 3.1.0 installed. So it is definitely not due to the R path having spaces.

* 编辑 *

我终于得到了这份工作!需要将 Rtools 目录添加到 PATH.

I finally got this work! Needed to add the Rtools directories to PATH.

推荐答案

正如问题中所暗示的,您需要将两个目录添加到 Windows PATH 环境变量:

As hinted at in the question, you need to add two directories to the Windows PATH environment variable:

  1. Rtools 可执行目录,可能在 C:\Rtools\bin.

gcc 可执行目录,可能在 C:\Rtools\gcc-4.6.3\bin.

The gcc executable directory, probably in C:\Rtools\gcc-4.6.3\bin.

您可能需要重新启动 Windows,R 才能看到新的 PATH.

You'll likely need to reboot Windows in order for R to be able to see the new PATH.

您可以只为当前 R 会话添加更新路径环境变量,使用类似:

You can add update the path environment variable for the current R session only, using something like:

rtools <- "C:\\Rtools\\bin"
gcc <- "C:\\Rtools\\gcc-4.6.3\\bin"
path <- strsplit(Sys.getenv("PATH"), ";")[[1]]
new_path <- c(rtools, gcc, path)
new_path <- new_path[!duplicated(tolower(new_path))]
Sys.setenv(PATH = paste(new_path, collapse = ";"))

这篇关于内联函数代码无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆