【问题标题】:Compiling RInside programs on Windows [duplicate]在 Windows 上编译 RInside 程序 [重复]
【发布时间】:2012-10-17 07:03:42
【问题描述】:

可能重复:
Problem with compiling RInside examples under Windows

在 Windows XP 上:

> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
> 

我尝试编译 Dirk 写的最简单的程序:

#include <RInside.h>                    // for the embedded R via RInside

int main(int argc, char *argv[]) {

    RInside R(argc, argv);              // create an embedded R instance

    R["txt"] = "Hello, world!\n";   // assign a char* (string) to 'txt'

    R.parseEvalQ("cat(txt)");           // eval the init string, ignoring any returns

    exit(0);
}

环境变量 PATH 全部包含:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\R\batchfiles_0.6-6;C:\R\Rtools\bin;C:\R\Rtools\MinGW\bin;C:\Program Files\GnuWin32;C:\"Program Files"\R\R-2.15.1\;

我从 Windows XP 中 RInside 的现有 R 示例中复制了这个 Makefile。

## -*- mode: make; tab-width: 8; -*-
##
## Simple Makefile
##
## TODO: 
##  proper configure for non-Debian file locations,   [ Done ]
##  allow RHOME to be set for non-default R etc

## comment this out if you need a different version of R, 
## and set set R_HOME accordingly as an environment variable
R_HOME :=       C:\"Program Files"\R\R-2.15.1\

sources :=      $(wildcard *.cpp)
programs :=         $(sources:.cpp=)


## include headers and libraries for R 
RCPPFLAGS :=        $(shell $(R_HOME)/bin/R CMD config --cppflags)
RLDFLAGS :=         $(shell $(R_HOME)/bin/R CMD config --ldflags)
RBLAS :=        $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
RLAPACK :=      $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)

## if you need to set an rpath to R itself, also uncomment
#RRPATH :=      -Wl,-rpath,$(R_HOME)/lib

## include headers and libraries for Rcpp interface classes
RCPPINCL :=         $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RCPPLIBS :=         $(shell echo 'Rcpp:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)


## include headers and libraries for RInside embedding classes
RINSIDEINCL :=      $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RINSIDELIBS :=      $(shell echo 'RInside:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)

## compiler etc settings used in default make rules
CXX :=          $(shell $(R_HOME)/bin/R CMD config CXX)
CPPFLAGS :=         -Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)
CXXFLAGS :=         $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
LDLIBS :=       $(RLDFLAGS) $(RRPATH) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)

all:            $(programs)
            @test -x /usr/bin/strip && strip $^

run:            $(programs)
            @for p in $(programs); do echo; echo "Running $$p:"; ./$$p; done

clean:
            rm -vf $(programs)
            rm -vrf *.dSYM

runAll:
            for p in $(programs); do echo "Running $$p"; ./$$p; done

这是我在 C 盘的 R 文件夹:

我看到了this thread,但我在 R 文件夹中没有 site-library 这样的东西。

我将R_HOME改成了C:\"Program Files"\R\R-2.15.1,导致出现以下错误:

【问题讨论】:

  • @DirkEddelbuettel 我已经看到了,问题的原因不一样,IMO。

标签: windows r makefile rinside


【解决方案1】:

它失败了,因为您在 C:\Program Files\R 中安装了 R,即使 FAQ for R on Windows 告诉您不要将 R 安装在带有空格的路径中。请参阅“问题 2.2:如何为 Windows 安装 R”:

如果您希望能够从源代码构建包,我们建议 您选择的安装路径不包含空格。

Rcpp / RInside 文档重复了该建议。 不要将 R 安装在带有空格的路径中。 如果必须,您必须修复 Makefile 以避免路径扩展中断。

【讨论】:

  • 感谢您处理这个基本问题。
  • Dirk,既然你在这里,我想确认 RInside 现在“确实”在 Windows 上运行而没有分段错误?你在另一个线程中说RInside 0.2.5, on CRAN as of today, restores the Windows functionality--using the fix James notes in the other comment.。这是否意味着seg fault问题现在已经完全解决了?
  • 是的,正如在我的博客上反复声明的那样,CRAN 测试和汽车制造商、R-Forge 汽车制造商、名单上的许多用户都证明了这一点,在这里,...
  • 我查看了您的 RInside 博客,但可能错过了信息。感谢顺便说一句。
  • "它失败了,因为你在 C:\Program Files\R 中安装了 R,尽管 Windows 上 R 的常见问题解答告诉你不要将 R 安装在带有空格的路径中。请参阅“问题 2.2:如何做我为 Windows 安装 R":" 为什么不把责任放在安装程序上,而不是埋在一个告诉用户他们需要修改默认安装的文档中。这实际上是埋在某个地方,不知道要寻找什么,除非被指出,否则没人会找到它(我也正在编译麻烦 atm 并正在阅读)
【解决方案2】:

你的路径对我来说是完全错误的:如果你的 R 主路径只是 C:\R ,为什么你使用 C:\R\Rtools\bin 作为 R_HOME ? 如果您的 R 文件夹是您在屏幕截图中显示的内容,顺便说一句,您的类路径也完全错误!

【讨论】:

  • 我的错,我不知道我在这里做什么。等等,我试试看会发生什么。
  • 更改 windows PATH 并询问您的同事正确的文件路径!
  • 这并没有太大帮助,再次导致了一些错误。我会发布截图。
  • BTW, also your classpath is totally wrong! 请告诉我如何找到正确的路径。这里没有人可以帮助我。
  • 我又添加了截图。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多