gpt4 book ai didi

autoconf - 为 r 包写入 `configure` 文件

转载 作者:行者123 更新时间:2023-12-04 18:56:52 26 4
gpt4 key购买 nike

我正在编写一个 r 包,它为 libSBML 提供了一个包装器。中号library .

我正在使用 rcppgsl package作为引用,它查找头文件和 GNU 科学库 GSL 的库文件的位置并使用该信息编写 configure脚本和 MakevarsMakevars.in .我目前不是为 Windows 构建的。在我的机器 (macOS) 上,libsbml (SBML C 库)安装在通常的位置,即

头文件位于 - /usr/local/include/sbml
和库文件 - /usr/local/lib .确实,如果在我的包裹里 Makevars我使用以下文件,我可以构建我的 package .

CXX=clang++
PKG_CPPFLAGS= -I/usr/local/include
PKG_LIBS= $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) /usr/local/lib/libsbml-static.a

但是,我想学习如何使用 configure脚本来查找库并使用该信息来构建包。 configure.ac 的相关部分来自 rcppgsl
## Check for non-standard programs: gsl-config(1)
AC_PATH_PROG([GSL_CONFIG], [gsl-config])
## If gsl-config was found, let's use it
if test "${GSL_CONFIG}" != ""; then
# Use gsl-config for header and linker arguments
GSL_CFLAGS=`${GSL_CONFIG} --cflags`
GSL_LIBS=`${GSL_CONFIG} --libs`
else
AC_MSG_ERROR([gsl-config not found, is GSL installed?])
fi

我替换了 GSL_CONFIGLIB_SBML在相关的地方,即整个 configure.ac我正在使用的文件粘贴在下面(最后)。

但是,我没有看到 configure , MakevarsMakevars.in正在生成(我在 rcppgsl 中看到)。这里的任何帮助将不胜感激!

为了完成,输出 ls -l | grep sbml (在 usr/local/include 中)是
drwxrwxr-x   58 root      admin    1856 Aug  1  2016 sbml

ls -l | grep sbml (在 usr/local/lib 中)是
-rw-r--r--   1 root      wheel   7970584 Aug  2  2016 libsbml-static.a
-rwxr-xr-x 1 arcadmin staff 10453624 Nov 25 2014 libsbml.5.11.0.dylib
-rwxr-xr-x 1 root wheel 3813572 Aug 2 2016 libsbml.5.13.0.dylib
lrwxr-xr-x 1 root wheel 20 Aug 1 2016 libsbml.5.dylib -> libsbml.5.13.0.dylib
-rw-r--r-- 1 root wheel 13907656 Feb 26 2015 libsbml.a
lrwxr-xr-x 1 arcadmin staff 15 Mar 27 2015 libsbml.dylib -> libsbml.5.dylib
-rwxr-xr-x 1 root wheel 828 Feb 26 2015 libsbml.la
-rwxrwxr-x 1 root admin 13362732 Nov 25 2014 libsbmlj.jnilib

我的 configure.ac文件 -
## Process this file with autoconf to produce a configure script.
##
## Configure.ac for RcppSBML
##
## Copyright (C) 2010 Romain Francois and Dirk Eddelbuettel
## Copyright (C) 2014 - 2015 Dirk Eddelbuettel
##
## Licensed under GNU GPL 2 or later

# The version set here will propagate to other files from here
AC_INIT([Rcppsbml], 0.1.0)

# Checks for common programs using default macros
AC_PROG_CC

## Use gsl-config to find arguments for compiler and linker flags
##
## Check for non-standard programs: gsl-config(1)
AC_PATH_PROG([LIB_SBML], [libsbml])
## If gsl-config was found, let's use it
if test "${LIB_SBML}" != ""; then
# Use gsl-config for header and linker arguments
SBML_CFLAGS=`${LIB_SBML} --cflags`
SBML_LIBS=`${LIB_SBML} --libs`
else
AC_MSG_ERROR([libsbml not found, is SBML installed?])
fi

# Now substitute these variables in src/Makevars.in to create src/Makevars
AC_SUBST(LIB_SBML)
AC_SUBST(LIB_SBML)

AC_OUTPUT(src/Makevars)

最佳答案

这是一个最小的设置:

删除 src/Makevars并创建 src/Makevars.in有内容

PKG_CPPFLAGS= @SBML_INCLUDE@
PKG_LIBS= $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) @SBML_LIBS@

我没有设置 CXX因为您无法在 src/Makevars 中更改它, 引用 Package build ignores Makevars flags .

创建一个最小的 configure.ac文件:
AC_INIT([Rcppsbml], 0.1.0)

AC_LANG(C++)
AC_REQUIRE_CPP
AC_PROG_CXX

# default values
AC_SUBST([SMBL_INCLUDE], "-I/usr/local/include")
AC_SUBST([SMBL_LIBS], "/usr/local/lib/libsbml-static.a")

# allow for override
AC_ARG_WITH([smbl],
AC_HELP_STRING([--with-smbl=PREFIX],
[path to where smbl is installed]),
[
SMBL_INCLUDE="-I${with_smbl}/include"
SMBL_LIBS="${with_smbl}/lib/libsbml-static.a"
],
[])

# create and report output
AC_CONFIG_FILES([src/Makevars])
AC_OUTPUT
echo
echo "Final src/Makevars"
cat src/Makevars

调用 autoconf创建 configure来自您的 configure.ac 的文件模板。您可能想使用 ./configure 检查脚本和 ./configure --with-smbl=/some/path .

称呼
R CMD build ...
R CMD check [--install-args=--configure-args=--with-smbl=/some/path] ...
R CMD INSTALL [--configure-args=--with-smbl=/some/path]...

构建、检查和安装包。

可能的扩展:
  • 允许在静态和动态链接之间切换。
  • 检查是否可以在指定位置找到处于可用状态的 SMBL。


  • 我在这里看到三个问题:
  • configure的一代|来自 configure.ac不是自动的。您必须调用 autoconf .
  • 同样,Makevars.in不是系统生成的。您必须将其作为模板提供,Makevarsconfigure 生成.
  • GSL 随附 gsl-config ,其他库使用通用 pkg-config .如果您的库不支持此功能,您可以使用更传统的方式来使用默认位置或 --with-... 提供的位置。论据。例如 RcppArrayFire I use :
    AC_SUBST([AF_INCLUDE], "")
    AC_SUBST([AF_LIBS], "-laf")

    AS_IF([test -e "${with_arrayfire}"],
    [
    AF_INCLUDE="-I${with_arrayfire}/include ${AF_INCLUDE}"
    AF_LIBS="-L${with_arrayfire}/lib ${AF_LIBS} -Wl,-rpath,${with_arrayfire}/lib"
    ])

    如果目录提供为 --with-arrayfire=/relevant/path ,然后在适当的子目录中搜索头文件和动态库。
  • 关于autoconf - 为 r 包写入 `configure` 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50539270/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com