【问题标题】:Error when installing xml2 package on Mavericks在 Mavericks 上安装 xml2 包时出错
【发布时间】:2023-03-14 16:47:01
【问题描述】:

我正在尝试在 R 中安装 devtools 包,并且需要安装它的依赖项 xml2,但我收到以下错误消息。

> install.packages("xml2")
Installing package into ‘/Users/xlong3/Library/R/3.2/library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/xml2_0.1.2.tar.gz'
Content type 'application/x-gzip' length 74808 bytes (73 KB)
==================================================
downloaded 73 KB

* installing *source* package ‘xml2’ ...
** package ‘xml2’ successfully unpacked and MD5 sums checked
Found pkg-config cflags and libs!
Using PKG_CFLAGS=-I/Users/xlong3/anaconda/include/libxml2
Using PKG_LIBS=-L/Users/xlong3/anaconda/lib -lxml2 -lz -liconv -lm
** libs
clang++ -I/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/include -DNDEBUG -I/Users/xlong3/anaconda/include/libxml2 -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I"/Users/xlong3/Library/R/3.2/library/Rcpp/include" -I"/usr/local/lib/R/3.2/site-library/BH/include"   -fPIC  -g -O2  -c RcppExports.cpp -o RcppExports.o
clang++ -I/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/include -DNDEBUG -I/Users/xlong3/anaconda/include/libxml2 -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I"/Users/xlong3/Library/R/3.2/library/Rcpp/include" -I"/usr/local/lib/R/3.2/site-library/BH/include"   -fPIC  -g -O2  -c connection.cpp -o connection.o
clang++ -I/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/include -DNDEBUG -I/Users/xlong3/anaconda/include/libxml2 -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I"/Users/xlong3/Library/R/3.2/library/Rcpp/include" -I"/usr/local/lib/R/3.2/site-library/BH/include"   -fPIC  -g -O2  -c xml2_doc.cpp -o xml2_doc.o
clang++ -I/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/include -DNDEBUG -I/Users/xlong3/anaconda/include/libxml2 -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I"/Users/xlong3/Library/R/3.2/library/Rcpp/include" -I"/usr/local/lib/R/3.2/site-library/BH/include"   -fPIC  -g -O2  -c xml2_init.cpp -o xml2_init.o
clang++ -I/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/include -DNDEBUG -I/Users/xlong3/anaconda/include/libxml2 -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I"/Users/xlong3/Library/R/3.2/library/Rcpp/include" -I"/usr/local/lib/R/3.2/site-library/BH/include"   -fPIC  -g -O2  -c xml2_namespace.cpp -o xml2_namespace.o
clang++ -I/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/include -DNDEBUG -I/Users/xlong3/anaconda/include/libxml2 -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I"/Users/xlong3/Library/R/3.2/library/Rcpp/include" -I"/usr/local/lib/R/3.2/site-library/BH/include"   -fPIC  -g -O2  -c xml2_node.cpp -o xml2_node.o
clang++ -I/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/include -DNDEBUG -I/Users/xlong3/anaconda/include/libxml2 -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I"/Users/xlong3/Library/R/3.2/library/Rcpp/include" -I"/usr/local/lib/R/3.2/site-library/BH/include"   -fPIC  -g -O2  -c xml2_url.cpp -o xml2_url.o
clang++ -I/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/include -DNDEBUG -I/Users/xlong3/anaconda/include/libxml2 -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I"/Users/xlong3/Library/R/3.2/library/Rcpp/include" -I"/usr/local/lib/R/3.2/site-library/BH/include"   -fPIC  -g -O2  -c xml2_xpath.cpp -o xml2_xpath.o
clang++ -I/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/include -DNDEBUG -I/Users/xlong3/anaconda/include/libxml2 -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I"/Users/xlong3/Library/R/3.2/library/Rcpp/include" -I"/usr/local/lib/R/3.2/site-library/BH/include"   -fPIC  -g -O2  -c xml_push.cpp -o xml_push.o
clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/lib -L/usr/local/opt/gettext/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/openssl/lib -o xml2.so RcppExports.o connection.o xml2_doc.o xml2_init.o xml2_namespace.o xml2_node.o xml2_url.o xml2_xpath.o xml_push.o -L/Users/xlong3/anaconda/lib -lxml2 -lz -liconv -lm -F/usr/local/Cellar/r/3.2.2_1/R.framework/.. -framework R -lintl -Wl,-framework -Wl,CoreFoundation
installing to /Users/xlong3/Library/R/3.2/library/xml2/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/Users/xlong3/Library/R/3.2/library/xml2/libs/xml2.so':
  dlopen(/Users/xlong3/Library/R/3.2/library/xml2/libs/xml2.so, 6): Library not loaded: libxml2.2.dylib
  Referenced from: /Users/xlong3/Library/R/3.2/library/xml2/libs/xml2.so
  Reason: image not found
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Users/xlong3/Library/R/3.2/library/xml2’

The downloaded source packages are in
    ‘/private/tmp/RtmpJc4WKq/downloaded_packages’
Warning message:
In install.packages("xml2") :
  installation of package ‘xml2’ had non-zero exit status
>




> version
               _                           
platform       x86_64-apple-darwin13.4.0   
arch           x86_64                      
os             darwin13.4.0                
system         x86_64, darwin13.4.0                                              
version.string R version 3.2.2 (2015-08-14)
nickname       Fire Safety   

【问题讨论】:

  • configure 发现libxml2 时,还有其他问题。这可能是PATH 问题,但您有一个有趣的设置。既然您使用 Homebrew for R 为什么不使用 Homebrew for libxml2?我会从 Homebrew 安装 libxml2,从 PATH 中删除 Anaconda,然后重新尝试构建。
  • 是的,我做了 home-brew libxml2: brew install libxml2 Warning: libxml2-2.9.2 already installed ,它不工作。
  • 可能是这种情况,但它在/Users/xlong3/anaconda/include/libxml2 找到它,所以你的设置非常混乱。
  • 我将 PATH 重置为 PATH=/usr/bin:/usr/sbin:/bin:/sbin : echo $PATH /usr/bin:/usr/sbin:/bin:/sbin 但是虽然我 install.packages("xml2"),它仍然告诉我它在 /Users/xlong3/anaconda/include/libxml2 找到它。配置文件可能在哪里,我可以更改它找到 libxml2 的位置吗?
  • 它在 configure 中运行 pkg-config(或 pkgconfig 我不记得是哪个)。重置 PATH 后是否重新启动了 R?

标签: r libxml2 devtools


【解决方案1】:

问题是“pkg-config”专门寻找“libxml2.pc”,而您安装的文件名为“libxml-2.0.pc”。如果您在现有文件和 pkg-config 预期的文件之间手动创建符号链接,它应该可以解决该错误。

这样的事情(在与文件相同的目录中完成)应该可以工作 $ ln -s libxml-2.0.pc libxml2.pc

【讨论】:

    【解决方案2】:

    我不确定我应该如何处理以下情况:

       pkg-config --libs --cflags  libxml2
    

    在 pkg-config 搜索路径中找不到包 libxml2。 也许您应该添加包含“libxml2.pc”的目录 到 PKG_CONFIG_PATH 环境变量 找不到包“libxml2”

    brew ls libxml2

    /usr/local/Cellar/libxml2/2.9.2/bin/xml2-config
    /usr/local/Cellar/libxml2/2.9.2/bin/xmlcatalog
    /usr/local/Cellar/libxml2/2.9.2/bin/xmllint
    /usr/local/Cellar/libxml2/2.9.2/include/libxml2/ (47 files)
    /usr/local/Cellar/libxml2/2.9.2/lib/libxml2.2.dylib
    /usr/local/Cellar/libxml2/2.9.2/lib/cmake/libxml2/libxml2-config.cmake
    /usr/local/Cellar/libxml2/2.9.2/lib/pkgconfig/libxml-2.0.pc
    /usr/local/Cellar/libxml2/2.9.2/lib/ (3 other files)
    /usr/local/Cellar/libxml2/2.9.2/share/aclocal/libxml.m4
    /usr/local/Cellar/libxml2/2.9.2/share/doc/ (153 files)
    /usr/local/Cellar/libxml2/2.9.2/share/gtk-doc/ (55 files)
    /usr/local/Cellar/libxml2/2.9.2/share/man/ (4 files)
    

    【讨论】:

      【解决方案3】:

      尝试更换你的 CRAN 镜像

      【讨论】: