c - 如何使用 AC_CONFIG_SUBDIR 将 C 和 Fortran 库打包在一起,其中 C 依赖于 Fortran 库?
问题描述
我有一个 C 库 GPTL,它是用 libtool 构建的。(https://github.com/jmrosinski/GPTL)
我有一个 Fortran 包装库 GPTL-fortran,它调用 C 库。(https://github.com/NOAA-GSD/GPTL-fortran)
我有第三个 github 存储库,GPTL-all。(https://github.com/NOAA-GSD/GPTL-all)。我想使用 AC_CONFIG_SUBDIR 让 GPTL-all 构建 C 和 fortran 库。
问题是 Fortran 库依赖于 C 库。单独构建时,首先构建并安装 C 库,然后构建 Fortran 库,并将 CPPFLAGS 和 LDFLAGS 设置为指向已安装 C 库的位置。
有没有办法通过安装 C 和 Fortran 库的组合包来实现这一点?
这是我到目前为止所拥有的:
# This is the autoconf file for GPTL-all, a combined C and Fortran
# library distribution.
AC_PREREQ([2.69])
AC_INIT([GPTL-all], [1.0.0], [edward.ha@noaa.gov])
# Find out about the host we're building on.
AC_CANONICAL_HOST
# Find out about the target we're building for.
AC_CANONICAL_TARGET
# Initialize automake.
AM_INIT_AUTOMAKE([foreign subdir-objects])
# Keep macros in an m4 directory.
AC_CONFIG_MACRO_DIR([m4])
# Set up libtool.
LT_PREREQ([2.4])
LT_INIT()
AC_CONFIG_FILES([Makefile])
AC_CONFIG_SUBDIRS([GPTL
GPTL-fortran])
AC_OUTPUT
但这失败了。当我运行配置时,它运行 C 库配置就好了。但是 fortran 库配置失败,因为它检查 C 库的存在:
checking for GPTLinitialize in -lgptl... no
configure: error: Can't find or link to the GPTL C library.
configure: error: ./configure failed for GPTL-fortran
如何让 GPTL-fortran 依赖于 GPTL?
解决方案
我通过在 Fortran 库构建中添加一个新选项来做到这一点:
# When built as part of the combined C/Fortran library distribution,
# the fortran library needs to be built with
# --enable-package-build. This tells the fortran library where to find
# the C library.
AC_ARG_ENABLE([package-build],
[AS_HELP_STRING([--enable-package-build],
[Set internally for package builds, should not be used by user.])])
test "x$enable_package_build" = xyes || enable_package_build=no
AM_CONDITIONAL([BUILD_PACKAGE], [test "x$enable_package_build" = xyes])
# Find the GPTL C library, unless this is a combined C/Fortran library
# build.
if test $enable_package_build = no; then
AC_CHECK_LIB([gptl], [GPTLinitialize], [],
[AC_MSG_ERROR([Can't find or link to the GPTL C library.])])
fi
从组合库配置启动此配置时,我添加了以下额外选项:
# Add this arg for the fortran build, to tell it to use the C library
# we just built.
ac_configure_args="$ac_configure_args --enable-package-build"
# Build the GPTL Fortran library.
AC_CONFIG_SUBDIRS([GPTL-fortran])
在 GPTL-fortran 测试目录 Makefile.am 中,我添加了以下内容:
# For combined C/Fortran builds, find the C library.
if BUILD_PACKAGE
LDADD = ${top_builddir}/../GPTL/src/libgptl.la
endif
因此,当进行包构建时,它会在 ../GPTL/src 中查找 GPTL 库,而对于非包构建,GPTL C 库位于 configure.ac 中。
推荐阅读
- javascript - NodeJS 无法正确加载其他文件
- javascript - 使用观察者检测元素何时出现
- php - php没有从freegeoip.net获取邮政编码
- alexa-skills-kit - alexa 不响应未处理的意图,而是调用我创建的任何自定义意图
- javascript - 使用模板使用的所有 CSS 规则生成一个内置的 angular index.html 页面?
- excel - 通过“结果”在 VBA 中查找
- c++ - 为什么类内部不允许初始化静态成员变量,但允许初始化 const 静态成员?
- html - 本地 HREF="" 标记未将一个页面链接到另一个页面
- android - 我可以使用 Facebook API 在群组上发帖吗?
- sql - 复制数据表到数据库 asp VB