【问题标题】:Setting up configure/makevars for libcouchbase in R?在 R 中为 libcouchbase 设置 configure/makevars?
【发布时间】:2014-04-25 15:17:24
【问题描述】:

我正在创建一个新的 R 包,我想在其中调用外部 c 库 (libcouchbase)。

我的问题是如何让包构建系统在链接期间找到库。我正在使用类似 linux/ubuntu 的系统。

这是我迄今为止所做的:

创建一个configure.ac

AC_INIT(rcouchbase, version-0.1)
AC_CHECK_LIB([couchbase], [lcb_create], [],
             [AC_MSG_ERROR(Failed to locate libcouchbase >= 2.0.0)])
COUCHBASE_LIBS="$LIBS"
AC_SUBST(COUCHBASE_LIBS)
AC_OUTPUT(src/Makevars)

使用 autoconf 生成配置

system("autoconf configure.ac > configure | chmod +x configure")

创建一个makevars.in

# set by configure
COUCHBASE_LIBS = @COUCHBASE_LIBS@
PKG_LIBS = $(COUCHBASE_LIBS)

构建我的包:

当我构建我的包时,配置文件成功找到了

==> R CMD INSTALL --no-multiarch --with-keep.source rcouchbase

这里有一些重要的输出:

==> R CMD INSTALL --no-multiarch --with-keep.source rcouchbase

* installing to library ‘/home/agstudy/R/packages’
* installing *source* package ‘rcouchbase’ ...
checking for gcc... gcc
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 accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for lcb_create in -lcouchbase... yes
configure: creating ./config.status
config.status: creating src/Makevars
make: Nothing to be done for `all'.
** libs
installing to /home/agstudy/R/packages/rcouchbase/libs
** R
** 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 '/home/agstudy/R/packages/rcouchbase/libs/rcouchbase.so':
  /home/agstudy/R/packages/rcouchbase/libs/rcouchbase.so: undefined symbol: lcb_destroy
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/agstudy/R/packages/rcouchbase’

Exited with status 1.

那么有人知道我应该在 makevars/config 文件中添加什么来解决链接问题吗?

编辑添加共享库依赖:

ldd libcouchbase.so
    linux-vdso.so.1 =>  (0x00007fff0a7fe000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fea0a26e000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fea0a06a000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fea09ca1000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fea0a7c5000)

【问题讨论】:

  • 您的标签“全错”。这实际上只是一个关于 autoconf 的问题。您可以尝试在这里查看我的一些软件包,以及一些 autoconf 教程。
  • @DirkEddelbuettel 我删除了 rcpp 标签。

标签: r build couchbase autoconf


【解决方案1】:

当你说COUCHBASE_LIBS="$LIBS"时,谁在为你填写$LIBS

首先,尝试分解问题。你应该给我们碎片:src/Makevars.in,但是 不是生成的src/Makevars。是否列出了正确的库?

另外,查看/向我们展示R CMD INSTALL ... 输出。图书馆有链接步骤吗?
您发布的内容表明不是因为缺少 lcb_destroy 符号。

如果您想了解 Autotools / Automake,我已经回过几次 this (older) tutorial;您可能会发现它很有用。

编辑:你还是一头雾水。我们不想看到ldd libcouchbase;我们认为一个很好。 你的包没有加载,所以我们需要its链接步骤和its ldd输出。

即我的 RQuantLib 包在其 R CMD INSTALL 上结束

g++ -shared -o RQuantLib.so [many .o files removed] \
           -L/usr/lib -lQuantLib -L/usr/lib/R/lib -lR

这清楚地表明它确实与(必需的)QuantLib 库链接。

【讨论】:

  • LIBS 已满AC_CHECK_LIB。就我而言,我得到-lcoucbase
  • 好吧——这似乎很好地使用了 autoconf。但是libcouchbase.* 在您的系统库目录之一中吗? R 是否真的与它相关联?
  • 是的 /usr/local/lib/ 我有所有 *.so。当我使用 #include <libcouchbase/couchbase.h> 时,R 成功找到了我的 headerslaos
  • 请显示R CMD INSTALL 的链接步骤并在生成的.so 库上尝试ldd
  • 我添加了 ldd 输出但我不明白链接步骤?我正在使用 R 工作室。也许我应该在它的构建选项中添加一些东西。
猜你喜欢
  • 2017-09-21
  • 2015-03-31
  • 1970-01-01
  • 1970-01-01
  • 2018-11-05
  • 1970-01-01
  • 1970-01-01
  • 2011-06-27
相关资源
最近更新 更多