【问题标题】:R not recognizing GSL library undefined referencesR 不识别 GSL 库未定义的引用
【发布时间】:2019-05-13 02:36:24
【问题描述】:

我正在使用开发工具从 R 中的 github 安装一个包(链接:https://github.com/aliceyiwang/mvabund)。我已经安装了 Rtools,使用另一个包的说明(这里:https://cran.r-project.org/web/packages/dynr/vignettes/InstallationForUsers.pdf)并且那里的所有检查都表明 GSL 和 RTools 安装正确。

我已经设置了 Windows 系统环境变量 LIB_GSL("C:/R/local323")和 PATHS("C:/RTools/bin/", "C:/RTools/mingw_64/bin", "C:/R/R-3.5.1/bin"

我还在安装包之前在 R 中运行以下代码:

Sys.setenv("LIB_GSL" = "C:/R/local323")
Sys.setenv(BINPREF = "C:/Rtools/mingw_$(WIN)/bin/")
Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:/RTools/bin/",
                        "C:/RTools/mingw_64/bin", "C:/R/R-3.5.1/bin", sep = ";"))

问题:

当我跑步时:

devtools::install_github("aliceyiwang/mvabund")

代码启动良好并开始安装包。然而,当这种情况发生时,就会有一点:

[...excluded very long list of undefined references like that below...]
summary.o:summary.cpp:(.text+0x194c): undefined reference to `gsl_vector_free'
    collect2.exe: error: ld returned 1 exit status
    no DLL was created
    ERROR: compilation failed for package 'mvabund'
    * removing 'C:/R/R-3.5.1/library/mvabund'
    In R CMD INSTALL
    Error in i.p(...) : 
      (converted from warning) installation of package ‘C:/Users/Joshua/AppData/Local/Temp/RtmpsPp5oY/file2154340c11f8/mvabund_4.0.tar.gz’ had non-zero exit status

我的猜测是,在某个地方,这些函数的某些路径没有被正确定义。我究竟做错了什么?

我的会话信息是

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252    LC_MONETARY=English_Australia.1252
[4] LC_NUMERIC=C                       LC_TIME=English_Australia.1252    

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

other attached packages:
[1] usethis_1.4.0  devtools_2.0.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0        rstudioapi_0.8    magrittr_1.5      pkgload_1.0.2     R6_2.3.0          rlang_0.3.0.1    
 [7] tools_3.5.1       pkgbuild_1.0.2    sessioninfo_1.1.1 cli_1.0.1         withr_2.1.2       remotes_2.0.2    
[13] yaml_2.2.0        assertthat_0.2.0  digest_0.6.18     rprojroot_1.3-2   crayon_1.3.4      processx_3.2.1   
[19] callr_3.1.0       fs_1.2.6          ps_1.2.1          curl_3.2          testthat_2.0.1    memoise_1.1.0    
[25] glue_1.3.0        compiler_3.5.1    desc_1.2.0        backports_1.1.2   prettyunits_1.0.2
> 

【问题讨论】:

  • 只是猜测,但您通常必须在 R 之外设置环境变量(即“系统级别”),然后重新启动 R 才能生效。另请注意,i)mvabund 在 CRAN 上 ii)您可以从 CRAN 安装它 iii)它几乎是使用 Rcpp 的最古老的软件包,所以我们有将近 10 年的时间来完成这项工作 iv)它在 win-builder 上可靠地工作在 CRAN 上。所以无论有什么问题都在你身边——也许是时候重新审视 R 手册“编写 R 扩展”和“安装和管理”以及 winbuilder 等关于 GSL 和变量的内容了。在 Linux 上一切正常......
  • 感谢您的评论 - 我意识到我可以从 CRAN 安装 mvabund,但它没有最新版本。我已经在 R 外部设置了环境变量,然后重新启动了 R。然后我也在 R 内部设置了环境变量。不幸的是,Linux 对我没有好处。
  • 我会回溯并移除移动部件——标准调试技巧。一旦install.packages("mvabund") 工作,我相信所需的GH 安装也会。在此之前,您目前正在与我无法接受的更多混淆层作斗争。
  • 我用install.packages("mvabund") 安装了 mvabund,然后再次运行 github 安装。但是,同样的错误仍然存​​在......
  • 我的想法。我忘记了您在 Windows 上,您可以从 CRAN 获得预构建二进制文件。所以这证明不了。回给你调试。尝试从 CRAN(或从本地 .tar.gz)安装源代码。

标签: r devtools gsl rtools


【解决方案1】:

我将包含这个问题的全部答案,因为它在一个地方没有其他地方存在,它修复了这个问题中的错误,并且在这个问题中:Installing R package from github returns non-zero exit status error; GSL and Rtools correctly installed

在做任何事情之前,请确保 R 没有安装到文件名中有空格的位置。例如,我们不想要 C:\Program Files\R,因为它有一个空格,而且众所周知,空格会让死亡机器人进入,这会破坏您的安装。

然后安装 RTools(并且,当您安装 RTools 时:文件名中没有空格...可能需要一段时间才能安装)和 GSL 库,非常接近此处的 Windows 说明:

https://cran.r-project.org/web/packages/dynr/vignettes/InstallationForUsers.pdf

(此处为 R 的 GSL 库: http://www.stats.ox.ac.uk/pub/Rtools/libs.html Rtools here - 下载最新的 Frozen 版本(现在:Rtools34.exe): https://cran.r-project.org/bin/windows/Rtools/)

然后我们从https://github.com/aliceyiwang/mvabund下载压缩包 并将其解压缩到我们的工作目录中。

现在,使用上述安装方法,GSL 库位于两个文件夹中,一个用于 i386 和 x64 架构。不幸的是,mvabund github 版本中的 Makevars.win 文件没有设置来区分该设置中的体系结构,因为它只有一个 PKG_LIBS 路径。

所以,清除 Makevars.win 文件并将其替换为:

## This assumes that the LIB_GSL variable points to working GSL libraries
CXX_STD = CXX11
ARCH=x64
ifeq "$(WIN)" "64"
ARCH= i386
else
ARCH= x64
endif
PKG_CPPFLAGS = -I$(LIB_GSL)/include -I. -I../inst/include
PKG_LIBS=-L"$(LIB_GSL)\lib"$(R_ARCH_BIN) -lgsl -lgslcblas 

然后我们运行以下代码。用您的文件路径替换文件路径。

Sys.setenv("LIB_GSL" = "C:/R/local323") # Replace file path here; this is the GSL library location, same as you specified for LIB_GSL in the windows environment 
Sys.setenv(BINPREF = "C:/Rtools/mingw_$(WIN)/bin/") # Replace file path here
Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:/RTools/bin/", sep = ";")) # Replace file path here
Sys.setenv("PKG_LIBS"="-L$(LIB_GSL)/lib/$(R_ARCH_BIN) -lgsl -lgslcblas")
Sys.setenv("PKG_CPPFLAGS"="-I$(LIB_GSL)/include -I. -I../inst/include")

# this assumes you have unzipped the mvabund download in your working directory
file.rename("mvabund-master", "mvabund")
shell("R CMD build mvabund")
install.packages("mvabund_4.0.tar.gz", repos = NULL) #may need to replace file name
library("mvabund")

让我们进行分析,然后:

abund <- mvabund(dataset[,8:39]) #community matrix section of spreadsheet
treatment <- as.character(dataset$Treatment) #treatment variable
## pairwise comparison 
manyglm(abund ~ treatment) -> msolglm
anova(msolglm, pairwise.comp = treatment, nBoot = 9) #pairwise comparisons make it run longer

【讨论】:

  • 但是src/Makevars.win used by the CRAN version 也更简单。也许架构会为每个架构分别嵌入到环境变量中——我根本不知道。但我相信对 CRAN 和 win-builder 有效的方法,那就是 this file。 (然后,Alice 再次看到需要稍微更新一下......)
  • 我知道。在执行上述操作之前,我检查了这一点。然而,我想做的就是运行这个包,不管它是否是 CRAN 做事的方式,上面的答案是否有效。
  • 当然。不要迂腐,但为此也应该能够 a) 使用现有的src/Makevars.win 和 b) 编译/构建一个拱门,比如 64 位和 c) 相应的库位置。但无论如何 - 你让它工作。我只是不喜欢暗示比“上游”更了解的答案——我相信作者。
  • 我同意。我尝试了所有我能想到的方法来修复我的安装而不接触包。不过最后,我真的别无选择。我找不到其他解决方案。
  • 这太笨拙了,我宁愿在他妈的汇编中重新实现库
猜你喜欢
  • 2015-10-14
  • 1970-01-01
  • 2015-12-16
  • 2018-08-09
  • 1970-01-01
  • 2019-06-17
  • 2021-09-01
  • 1970-01-01
  • 2015-04-25
相关资源
最近更新 更多