【问题标题】:install.packages() can't find shared .so object fileinstall.packages() 找不到共享的 .so 目标文件
【发布时间】:2019-08-29 21:53:26
【问题描述】:

任何人都可以提出前进的道路吗?

在尝试安装 udunit2(R 包)时,我收到以下错误,表明它找不到共享对象文件。是否有我缺少的环境变量?

/srv/shiny-server/r-packages是我自定义的R包安装目录。

我根据https://www.unidata.ucar.edu/software/udunits/udunits-current/doc/udunits/udunits2.html#Obtain安装了udunits2

udunits2 用作命令行工具。

更新:libudunits2.so.0 似乎存在于我的系统上:

$ la /usr/local/lib
total 568
drwxr-xr-x.  3 root root   4096 Apr  4 14:56 ./
drwxr-xr-x. 12 root root   4096 Dec  8  2016 ../
-rw-r--r--.  1 root root 199466 Apr  4 14:56 libudunits2.a
-rwxr-xr-x.  1 root root    889 Apr  4 14:56 libudunits2.la*
lrwxrwxrwx.  1 root root     20 Apr  4 10:04 libudunits2.so -> libudunits2.so.0.1.0*
lrwxrwxrwx.  1 root root     20 Apr  4 10:04 libudunits2.so.0 -> libudunits2.so.0.1.0*
-rwxr-xr-x.  1 root root 131080 Apr  4 10:04 libudunits2.so.0.1.0*

我正在使用安装了 DevToolSet-7 的 Red Hat Enterprise 6.9 系统(所以,g++ 7.2.1)。

> install.packages("udunits2")
Installing package into ‘/srv/shiny-server/r-packages’
(as ‘lib’ is unspecified)
trying URL 'http://cran.us.r-project.org/src/contrib/udunits2_0.13.tar.gz'
Content type 'application/x-gzip' length 67182 bytes (65 KB)
==================================================
downloaded 65 KB

* installing *source* package ‘udunits2’ ...
** package ‘udunits2’ successfully unpacked and MD5 sums checked
checking for gcc... gcc -std=gnu99
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc -std=gnu99 accepts -g... yes
checking for gcc -std=gnu99 option to accept ISO C89... none needed
checking for XML_ParserCreate in -lexpat... yes
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking udunits2.h usability... yes
checking udunits2.h presence... yes
checking for udunits2.h... yes
checking for ut_read_xml in -ludunits2... yes
configure: creating ./config.status
config.status: creating src/Makevars
** libs
gcc -std=gnu99 -I/usr/local/lib64/R/include -DNDEBUG  -I/usr/local/include    -fpic  -I/include  -c udunits2_R.c -o udunits2_R.o
gcc -std=gnu99 -shared -L/lib -o udunits2.so udunits2_R.o -ludunits2 -lexpat -lexpat -ludunits2
installing to /srv/shiny-server/r-packages/udunits2/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 '/srv/shiny-server/r-packages/udunits2/libs/udunits2.so':
  libudunits2.so.0: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/srv/shiny-server/r-packages/udunits2’

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

【问题讨论】:

    标签: r


    【解决方案1】:

    您误读了错误消息。它实际上说

    libudunits2.so.0: cannot open shared object file: No such file or directory
    

    您可以通过执行 RHEL 等效项来解决此问题

    sudo apt-get install libudunits2-dev
    

    获取构建所需的标头和可链接库,除了您可能已经拥有的libudunits2,它只允许您运行共享对象代码,但不能链接到它。

    对于apt-get 示例的道歉,我无法快速为您搜索yum原理还是一样:你需要匹配的-dev包。

    【讨论】:

    • 我认为我没有误读它......虽然我在原来的帖子标题中说错了......我已经更新了帖子以指出 libudunits2.so.0 确实,已经存在——当我从源代码安装 udunits2 时创建并安装,我想......我已经通过将 libudunits2.* 文件复制到 /lib 成功安装了 R 包(udunits2)——但这显然不是我应该的方式已经完成了...如何将额外的库目录传递给通常的 R install.packages()?
    • 或者更确切地说:如何让 R 在包加载时也查看 /usr/local/lib/ 的 DLL?
    • 您似乎对 system 共享库的角色感到困惑。您需要来自 UCAR 的(非 R)库 udunits。我从 Debian / Ubuntu 得到这个现成的;您可能需要查看 rpm 或从源代码安装。 这一步与CRAN包无关。完成后,你就有了一个新的系统库,你可以再次尝试install.packages("udunits2")
    • 我显然对某些事情感到困惑,但事实并非如此,德克。我认为我的原始帖子清楚地表明(在系统级别)我 安装了 udunits2 和 libudunits2-devel。我还清楚地表明(在 R 中)install.packages 不起作用,因为它找不到已经安装的 libudunits2.so,它位于我的 RHEL 上的 /usr/local/lib/ 中。如果我cp /usr/local/lib/libudunits2* /lib/ 那么我可以成功安装.packages。我可以 ln -s 代替......但是有没有更直接的方法来告诉 R 包含 /usr/local/lib/ ?它只是使用用户的 $PATH 吗?还有什么?
    • 我不知道。 20 多年来,我一直在为 CRAN 和 CRAN 构建软件包。由于外部库,这曾经是一个挑战;对我来说,这不再是一个挑战,因为它只适用于 Debian / Ubuntu 提供的 libudunit2 就像数以万计的其他软件包一样(因为您可以轻松地在 Debian docker 容器或其他虚拟环境中进行测试) .因此,您的麻烦可能与 RHEL 相关,或者可能是由于我们彼此交谈。真的很抱歉,但我不能再帮你了,祝你好运。
    【解决方案2】:

    试试这个:

    在 R 控制台中,运行:

    Sys.setenv(UDUNITS2_LIBS="/path/to/udunits2/lib")
    Sys.setenv(UDUNITS2_INCLUDE="/path/to/udunits2/include")
    

    然后

    install.packages("udunits2")
    

    更新

    此解决方案不再适用于我。从 ubuntu 存储库安装 libudunits-dev 有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-13
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 2010-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多