【发布时间】: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