R 安装包时找不到 GSL 库

发布于 2025-01-10 10:28:29 字数 2678 浏览 0 评论 0原文

我正在安装学术期刊补充材料中的软件包 (https://www.degruyter.com/document/doi/10.1515/snde-2012-0064/html?lang=en)。

我已经设置了 Windows 系统环境变量 LIB_GSL (作为“C:/R/local323”)和 PATHS (作为“C:/rtools40/bin/”、“C:/rtools/mingw64/bin”、“C:/ R/R-4.1.2/bin")

当我运行 install.packages("/cobreak_0.1.tar.gz", repos=NULL, type="source") 时,会发生这种情况

* installing *source* package 'cobreak' ...
** using staged installation
** libs
"C:/rtools40/mingw64/bin/"g++ -std=gnu++11  -I"C:/R/R-4.1.2/include" -DNDEBUG  -I'C:/Users/Phat/Documents/R/win-library/4.1/Rcpp/include' -I'C:/Users/Phat/Documents/R/win-library/4.1/RcppArmadillo/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c cointmdl.cc -o cointmdl.o
In file included from genmdl.h:5,
                 from cointmdl.cc:1:
random_arma.h:4:10: fatal error: gsl/gsl_rng.h: No such file or directory
 #include <gsl/gsl_rng.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
make: *** [C:/R/R-4.1.2/etc/x64/Makeconf:243: cointmdl.o] Error 1
ERROR: compilation failed for package 'cobreak'

我的猜测是问题出在 Makevars.win 文件中。这就是 Makevar 的样子

## This assume that we can call Rscript to ask Rcpp about its locations
## Use the R_HOME indirection to support installations of multiple R version
PKG_LIBS = $(shell $(R_HOME)/bin/Rscript.exe -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

更新: 我刚刚在这里链接发现了类似的问题。但是,按照说明进行操作后,我遇到了新的错误。这次是 boost 的问题

** libs
C:/rtools40/mingw64/bin/g++  -std=gnu++11 -I"C:/R/R-4.1.2/include" -DNDEBUG -IC:/R/local323/include -I. -I../inst/include -I'C:/Users/Phat/Documents/R/win-library/4.1/Rcpp/include' -I'C:/Users/Phat/Documents/R/win-library/4.1/RcppArmadillo/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c cointmdl.cc -o cointmdl.o
C:/rtools40/mingw64/bin/g++  -std=gnu++11 -I"C:/R/R-4.1.2/include" -DNDEBUG -IC:/R/local323/include -I. -I../inst/include -I'C:/Users/Phat/Documents/R/win-library/4.1/Rcpp/include' -I'C:/Users/Phat/Documents/R/win-library/4.1/RcppArmadillo/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c cpp_r_interface.cc -o cpp_r_interface.o
cpp_r_interface.cc:2:10: fatal error: boost/ptr_container/ptr_vector.hpp: No such file or directory
 #include <boost/ptr_container/ptr_vector.hpp>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

,我尝试安装“BH”包,但问题仍然存在。

有人对如何解决这个问题有任何想法吗?

I am installing a package from the Supplementary materials of an academic journal (https://www.degruyter.com/document/doi/10.1515/snde-2012-0064/html?lang=en).

I've set the Windows system environment variables LIB_GSL (as "C:/R/local323") and PATHS (as "C:/rtools40/bin/", "C:/rtools/mingw64/bin", "C:/R/R-4.1.2/bin")

When I run install.packages("/cobreak_0.1.tar.gz", repos=NULL, type="source"), this happens

* installing *source* package 'cobreak' ...
** using staged installation
** libs
"C:/rtools40/mingw64/bin/"g++ -std=gnu++11  -I"C:/R/R-4.1.2/include" -DNDEBUG  -I'C:/Users/Phat/Documents/R/win-library/4.1/Rcpp/include' -I'C:/Users/Phat/Documents/R/win-library/4.1/RcppArmadillo/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c cointmdl.cc -o cointmdl.o
In file included from genmdl.h:5,
                 from cointmdl.cc:1:
random_arma.h:4:10: fatal error: gsl/gsl_rng.h: No such file or directory
 #include <gsl/gsl_rng.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
make: *** [C:/R/R-4.1.2/etc/x64/Makeconf:243: cointmdl.o] Error 1
ERROR: compilation failed for package 'cobreak'

My guess is the issue was in the Makevars.win file. This is what the Makevars looks like

## This assume that we can call Rscript to ask Rcpp about its locations
## Use the R_HOME indirection to support installations of multiple R version
PKG_LIBS = $(shell $(R_HOME)/bin/Rscript.exe -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

Update:
I just found a similar problem here link. However, after following the instruction, I encounter a new error. This time it's a problem with boost

** libs
C:/rtools40/mingw64/bin/g++  -std=gnu++11 -I"C:/R/R-4.1.2/include" -DNDEBUG -IC:/R/local323/include -I. -I../inst/include -I'C:/Users/Phat/Documents/R/win-library/4.1/Rcpp/include' -I'C:/Users/Phat/Documents/R/win-library/4.1/RcppArmadillo/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c cointmdl.cc -o cointmdl.o
C:/rtools40/mingw64/bin/g++  -std=gnu++11 -I"C:/R/R-4.1.2/include" -DNDEBUG -IC:/R/local323/include -I. -I../inst/include -I'C:/Users/Phat/Documents/R/win-library/4.1/Rcpp/include' -I'C:/Users/Phat/Documents/R/win-library/4.1/RcppArmadillo/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c cpp_r_interface.cc -o cpp_r_interface.o
cpp_r_interface.cc:2:10: fatal error: boost/ptr_container/ptr_vector.hpp: No such file or directory
 #include <boost/ptr_container/ptr_vector.hpp>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

I tried to install the "BH" package but the problem still persists.

Does anyone have any ideas on how to fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

土豪 2025-01-17 10:28:30

所以我下载了你引用的 zip 存档并将其解压。它包含一个 R cobreak_0.1.tar.gz 乍一看似乎很合理:

Package: cobreak
Title: Regime-switching cointegration
Description: MCMC estimation of regime-switching cointegration models
Version: 0.1
Date: 2013-12-11
Author: Markus Jochmann
Maintainer: Markus Jochmann <[email protected]>
License: GPL (>= 2)
Depends: Rcpp (>= 0.9.15), RcppArmadillo (>= 0.3.4.3)
LinkingTo: Rcpp, RcppArmadillo
Packaged: 2013-12-11 16:03:39 UTC; markus

但是,当我尝试将它安装到我的 Linux 系统上时,它遇到了函数 sympd() 的问题 已调用但未定义:

edd@rob:~/Downloads/regimeswitchcoint/cobreak$ install.r .
* installing *source* package ‘cobreak’ ...
** using staged installation
** libs
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c cointmdl.cc -o cointmdl.o
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c cpp_r_interface.cc -o cpp_r_interface.o
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c dist_arma.cc -o dist_arma.o
dist_arma.cc: In function ‘double logpdfmn(const vec&, const mat&)’:
dist_arma.cc:52:37: error: ‘sympd’ was not declared in this scope
   52 |   result -= as_scalar( x.t() * inv( sympd( Sigma ) ) * x );
      |                                     ^~~~~
dist_arma.cc: In function ‘double logpdfmn(const vec&, const vec&, const mat&)’:
dist_arma.cc:62:39: error: ‘sympd’ was not declared in this scope
   62 |   result -= as_scalar( xmm.t() * inv( sympd( Sigma ) ) * xmm );
      |                                       ^~~~~
make: *** [/usr/lib/R/etc/Makeconf:175: dist_arma.o] Error 1
ERROR: compilation failed for package ‘cobreak’
* removing ‘/usr/local/lib/R/site-library/cobreak’
Warning message:
In install.packages(pkgs = f, lib = lib, repos = if (isMatchingFile(f)) NULL else repos) :
  installation of package ‘.’ had non-zero exit status
edd@rob:~/Downloads/regimeswitchcoint/cobreak$ 

从根本上讲,我不明白您为什么在 StackOverflow 上问这个问题。这是已发表并经过同行评审的作品,并且您会获得作者的姓名和地址(或者如果您必须是期刊编辑)。我会联系他们。

编辑 事实证明,这是由于“过时”的软件包源造成的,CRAN 存档会对此进行更改。正如犰狳文档所示,inv(sympd(...)) 不再可用,但 inv_sympd() 可用。在两行中进行更改允许构建和安装包。对我来说没有问题:

edd@rob:~/Downloads/regimeswitchcoint/cobreak$ install.r .
* installing *source* package ‘cobreak’ ...
** using staged installation
** libs
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c dist_arma.cc -o dist_arma.o
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c ext_arma.cc -o ext_arma.o
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c genmdl.cc -o genmdl.o
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c markovmdl.cc -o markovmdl.o
markovmdl.cc: In member function ‘void MarkovMdl::logisdXi(const mat&, arma::vec&)’:
markovmdl.cc:218:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘const uword’ {aka ‘const unsigned int’} [-Wsign-compare]
  218 |   for( int l=0; l<logp.n_elem; l++ )
      |                 ~^~~~~~~~~~~~
markovmdl.cc: In member function ‘void MarkovMdl::save_parmem(arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::imat&)’:
markovmdl.cc:521:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<arma::Mat<double> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  521 |   for( int i=0; i<ximem.size(); i++ )
      |                 ~^~~~~~~~~~~~~
markovmdl.cc: In member function ‘void MarkovMdl::save_parmem(arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::imat&)’:
markovmdl.cc:547:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<arma::Mat<double> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  547 |   for( int i=0; i<ximem.size(); i++ )
      |                 ~^~~~~~~~~~~~~
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c mvlinmdl.cc -o mvlinmdl.o
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c random_arma.cc -o random_arma.o
ccache g++-11 -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -Wl,-z,relro -o cobreak.so cointmdl.o cpp_r_interface.o dist_arma.o ext_arma.o genmdl.o markovmdl.o mvlinmdl.o random_arma.o -llapack -lblas -lgfortran -lm -lquadmath -lgsl -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/00LOCK-cobreak/00new/cobreak/libs
** R
** data
** byte-compile and prepare package for lazy loading
** help
No man pages found in package  ‘cobreak’ 
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (cobreak)
edd@rob:~/Downloads/regimeswitchcoint/cobreak$ 

编辑2:我应该补充一点,该包实际上确实具有未声明的依赖项,例如,如果想要与 GNU GSL 链接(即由包提供的系统库libgsl-dev (我是 Debian 维护者,但这是一个侧面细节))以及您注意到的 Boost 头文件的一个包含内容。总而言之,这反映了 SNDE 期刊的糟糕状况,编辑们应该执行更严格的再现性规则。这些现在更加常见,部分归功于 JStatSoft(我在其中担任副编辑)等期刊的领导,但旧论文的情况并非总是如此。无论如何:您可以构建这个包,您“只”需要学习如何在 Windows 上使用 GSL,这在 Windows 上的 R 支持材料中进行了记录。

So I downloaded the zip archive you referenced unpacked it. It contains an R cobreak_0.1.tar.gz which at first glance looks reasonable:

Package: cobreak
Title: Regime-switching cointegration
Description: MCMC estimation of regime-switching cointegration models
Version: 0.1
Date: 2013-12-11
Author: Markus Jochmann
Maintainer: Markus Jochmann <[email protected]>
License: GPL (>= 2)
Depends: Rcpp (>= 0.9.15), RcppArmadillo (>= 0.3.4.3)
LinkingTo: Rcpp, RcppArmadillo
Packaged: 2013-12-11 16:03:39 UTC; markus

However, when I try to install it on my Linux system it hits a wall over a function sympd() called but not defined:

edd@rob:~/Downloads/regimeswitchcoint/cobreak$ install.r .
* installing *source* package ‘cobreak’ ...
** using staged installation
** libs
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c cointmdl.cc -o cointmdl.o
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c cpp_r_interface.cc -o cpp_r_interface.o
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c dist_arma.cc -o dist_arma.o
dist_arma.cc: In function ‘double logpdfmn(const vec&, const mat&)’:
dist_arma.cc:52:37: error: ‘sympd’ was not declared in this scope
   52 |   result -= as_scalar( x.t() * inv( sympd( Sigma ) ) * x );
      |                                     ^~~~~
dist_arma.cc: In function ‘double logpdfmn(const vec&, const vec&, const mat&)’:
dist_arma.cc:62:39: error: ‘sympd’ was not declared in this scope
   62 |   result -= as_scalar( xmm.t() * inv( sympd( Sigma ) ) * xmm );
      |                                       ^~~~~
make: *** [/usr/lib/R/etc/Makeconf:175: dist_arma.o] Error 1
ERROR: compilation failed for package ‘cobreak’
* removing ‘/usr/local/lib/R/site-library/cobreak’
Warning message:
In install.packages(pkgs = f, lib = lib, repos = if (isMatchingFile(f)) NULL else repos) :
  installation of package ‘.’ had non-zero exit status
edd@rob:~/Downloads/regimeswitchcoint/cobreak$ 

Fundamentally, I do not understand why you asked this question at StackOverflow. This is published and peer-reviewed work, and you are given a name and address of an author (or if you must a journal editor). I would contact them.

Edit Turns out this is due to 'stale' package sources, a CRAN archive would have that changed. As the documentation for Armadillo shows, the inv(sympd(...)) is no longer available but inv_sympd(). Making that change on two lines allows the package to build and install. No issues for me:

edd@rob:~/Downloads/regimeswitchcoint/cobreak$ install.r .
* installing *source* package ‘cobreak’ ...
** using staged installation
** libs
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c dist_arma.cc -o dist_arma.o
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c ext_arma.cc -o ext_arma.o
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c genmdl.cc -o genmdl.o
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c markovmdl.cc -o markovmdl.o
markovmdl.cc: In member function ‘void MarkovMdl::logisdXi(const mat&, arma::vec&)’:
markovmdl.cc:218:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘const uword’ {aka ‘const unsigned int’} [-Wsign-compare]
  218 |   for( int l=0; l<logp.n_elem; l++ )
      |                 ~^~~~~~~~~~~~
markovmdl.cc: In member function ‘void MarkovMdl::save_parmem(arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::imat&)’:
markovmdl.cc:521:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<arma::Mat<double> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  521 |   for( int i=0; i<ximem.size(); i++ )
      |                 ~^~~~~~~~~~~~~
markovmdl.cc: In member function ‘void MarkovMdl::save_parmem(arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::mat&, arma::imat&)’:
markovmdl.cc:547:18: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<arma::Mat<double> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  547 |   for( int i=0; i<ximem.size(); i++ )
      |                 ~^~~~~~~~~~~~~
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c mvlinmdl.cc -o mvlinmdl.o
ccache g++-11 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppArmadillo/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c random_arma.cc -o random_arma.o
ccache g++-11 -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -Wl,-z,relro -o cobreak.so cointmdl.o cpp_r_interface.o dist_arma.o ext_arma.o genmdl.o markovmdl.o mvlinmdl.o random_arma.o -llapack -lblas -lgfortran -lm -lquadmath -lgsl -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/00LOCK-cobreak/00new/cobreak/libs
** R
** data
** byte-compile and prepare package for lazy loading
** help
No man pages found in package  ‘cobreak’ 
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (cobreak)
edd@rob:~/Downloads/regimeswitchcoint/cobreak$ 

Edit 2: I should add that the package does in fact have undeclared dependencies, for example if wants to link with GNU GSL (i.e. the system library provided for example by the package libgsl-dev on the Ubuntu system I use (and for which I am the Debian maintainer, but that is a side detail)) as well as the one inclusion of the Boost header file you noticed. So in sum this reflects poor on the SNDE journal where editors should have enforced stricter reproducibility rules. These are more common now, thanks in part due to leadership by journals such as JStatSoft (where I help as an Associate Editor) but that was not always the case with older papers. Anyway: you can build this package, you "just" need to learn how to use the GSL on Windows which is documented in the support material for R on Windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文