【问题标题】:how to specify which R lib to use when installing a R package?安装 R 包时如何指定使用哪个 R 库?
【发布时间】:2017-07-21 15:43:33
【问题描述】:

I was trying to use a R package called "XML", 但安装后无法使用:

# in R environment
> library("XML")
> XML::parseURI("")
Error in XML::parseURI("") : cannot parse URI 

问题原来是 R 找不到安装在我的目录中的当前版本的“libxml2”:

 echo $LD_LIBRARY_PATH /somewhere/Jun/Programme/libxml2-devel-2.9.1-2.1/usr/lib/:

检索有关链接到的 libxml2 库“XML”版本的信息

> path = unclass(getLoadedDLLs()[["XML"]])$path
> path
[1] "/misc/home/Jun/Programme/R-3.3.1/lib64/R/library/XML/libs/XML.so"
> system2("ldd",args=path)
                linux-vdso.so.1 =>  (0x00007fff2a9e8000)
                libxml2.so.2 => /usr/lib64/libxml2.so.2 (0x00002aefc088a000)  # XML is using a common "libxml2.so.2" not the one I installed. 
                libz.so.1 => //home/Jun/Programme/zlib-1.2.11/lib/libz.so.1 (0x00002aefc0bc8000)
                libm.so.6 => /lib64/libm.so.6 (0x00002aefc0de5000)
                libdl.so.2 => /lib64/libdl.so.2 (0x00002aefc1068000)
                ...

有什么建议吗?

为了使“XML”链接到安装在我的目录中的 libxml2, 我做了这样的努力:

  1. 为 libxml2 设置路径:

    回显 $LD_LIBRARY_PATH

    /somewhere/Jun/Programme/pcre-8.40/lib/:/somewhere/Jun/Programme/xz-5.2.3/lib/:/somewhere/Jun/Programme/zlib-1.2.11/include/:/某处/Jun/Programme/zlib-1.2.11/lib/:/somewhere/Jun/Programme/bzip2-1.0.6/lib/:/somewhere/Jun/Programme/bzip2-1.0.6/include/:/somewhere/ Jun/Programme/gcc-6.1.0/lib/:/somewhere/Jun/Programme/gcc-6.1.0/lib64/:/somewhere/Jun/Programme/libxml2-devel-2.9.1-2.1/usr/lib/ :/somewhere/Jun/Programme/curl-7.52.1/lib/:/somewhere/Jun/Programme/libtool_CentOS6_64/usr/lib64/:/home/appl/openmpi-1.3.1/lib:/opt22/lsf83_exp/8.3 /linux2.6-glibc2.3-x86_64/lib:/opt/ups/lib

  2. 使用“--enable”参数重新编译 R 并指定 lib 的配置

    ./configure --prefix=$HOME/Programme/R-3.3.1 --enable-R-shlib LDFLAGS="-L/$HOME/Programme/zlib-1.2.11/lib -L/$HOME /Programme/bzip2-1.0.6/lib -L/$HOME/Programme/xz-5.2.3/lib -L/$HOME/Programme/pcre-8.40/lib -L/$HOME/Programme/curl-7.52。 1/lib " CPPFLAGS="-I/$HOME/Programme/zlib-1.2.11/include -I/$HOME/Programme/bzip2-1.0.6/include -I/$HOME/Programme/xz-5.2.3 /include -I/$HOME/Programme/pcre-8.40/include -I/$HOME/Programme/curl-7.52.1/include"

  3. 使用配置参数安装“XML”:

    biocLite("XML",configure.args='--with-xml-config="/somewhere/Jun/Programme/libxml2-devel-2.9.1-2.1/usr/bin/xml2-config"') BioC_mirror:http://bioconductor.org 使用 Bioconductor 3.4 (BiocInstaller 1.24.0)、R 3.3.1 (2016-06-21)。 安装包‘XML’ 尝试 URL 'http://cran.rstudio.com/src/contrib/XML_3.98-1.5.tar.gz'

    内容类型 'application/x-gzip' 长度 1599213 字节 (1.5 MB)

    已下载 1.5 MB ...

但它们似乎都不起作用:

* installing *source* package ‘XML’ ...
** package ‘XML’ successfully unpacked and MD5 sums checked
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for sed... /bin/sed
checking for pkg-config... /usr/bin/pkg-config
User defined xml-config: /somewhere/Jun/Programme/libxml2-devel-2.9.1-2.1/usr/bin/xml2-config, XML Version: 2, XML2: yes
USE_XML2 = yes
SED_EXTENDED_ARG: -r
Minor 9, Patch 1 for 2.9.1
Located parser file -I/usr/include/libxml2/parser.h
checking for gzopen in -lz... yes
checking for xmlParseFile in -lxml2... yes
checking for xmlHashSize in -lxml2... yes
Using built-in xmlHashSize
Checking DTD parsing (presence of externalSubset)...
checking for xmlHashSize in -lxml2... yes
Found xmlHashSize
checking for xmlOutputBufferCreateBuffer in -lxml2... yes
have xmlOutputBufferCreateBuffer()
checking for xmlDocDumpFormatMemoryEnc in -lxml2... yes
checking libxml/xmlversion.h usability... yes
checking libxml/xmlversion.h presence... yes
checking for libxml/xmlversion.h... yes
Expat:  FALSE
Checking for return type of xmlHashScan element routine.
No return value for xmlHashScan
xmlNs has a context field
Checking for cetype_t enumeration
Using recent version of R with cetype_t enumeration type for encoding
checking for xmlsec1-config... /usr/bin/xmlsec1-config
nodegc default 
xml-debug default 
No XML_WITH_ZLIB enumeration value.
Version has xmlHasFeature()

****************************************
Configuration information:

Libxml settings

libxml include directory: -I/usr/include/libxml2
libxml library directory: -lxml2 -lz -lm -ldl -lz  -lxml2
libxml 2:                 -DLIBXML2=1

【问题讨论】:

  • /somewhere/Jun/Programme/libxml2-devel-2.9.1-2.1/usr/bin/xml2-config --cflags --libs 的输出是什么?
  • @nwellnhof,您好 nwellnhof ,您可能会怀疑,xml2-config --cflags -I/usr/include/libxml2 xml2-config --libs -lxml2 -lz -lm -ldl # the xml2-config points at the system libraries. 我的 xml2-config 没有指向我安装的库。我通过编译而不是使用“rpm”重新安装解决了我的问题。感谢您的关注和建议。

标签: r xml libxml2


【解决方案1】:

我想我已经找到了解决方案。而不是使用 rpm 安装“libxml2” (我很抱歉我没有在我的帖子中提到它;我没有意识到这可能是我的麻烦的原因),我应该从源代码编译“libxml2”。

对于有类似问题的人:

下载当前版本的libxml2http://www.linuxfromscratch.org/blfs/view/svn/general/libxml2.html

按照上面链接的说明进行操作。

安装两点:

1.

./configure --prefix=$HOME/Programme --disable-static --with-history --with-zlib=/somewhere/Jun/Programme/zlib-1.2.11 && make

你必须指定 zlib (--with);这也意味着您必须安装 zlib。我必须添加“--with”才能使configure 工作。

  1. 说明声明您必须以 root 用户身份调用“make install”,但不,您不必这样做。

  2. 为您安装的“libxml2”设置PATH

  3. 重新安装 R 包“XML”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-05
    • 2018-12-24
    • 2022-01-13
    • 1970-01-01
    • 2017-11-15
    • 1970-01-01
    • 2018-04-14
    • 1970-01-01
    相关资源
    最近更新 更多