我有一个用libtool构建的C库GPTL。 (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都建立C和fortran库。
问题在于Fortran库依赖于C库。单独构建时,首先构建并安装C库,然后使用CPPFLAGS和LDFLAGS设置为指向已安装C库的位置来构建Fortran库。
有没有一种方法可以通过安装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
但这失败了。当我运行configure时,它运行C库configure就可以了。但是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?
答案 0 :(得分:0)
我是通过向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
从组合库configure启动此configure时,我添加了以下额外选项:
# 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中。