Skip to content

Commit

Permalink
Remove FMS lib test; force LIBS in coupled builds
Browse files Browse the repository at this point in the history
We currently rely on an FMS library test to direct autoconf to prepend
-lFMS to the LIBS flag.  However, this conflicts with our explicit
setting of LIBS, which contains multiple libraries which also rely on
FMS, and must therefore precede -lFMS (in a POSIX-compliant linker, at
least).

Unless we create new macros for every library - and find a way to do so
for test functions with arguments - there is no way to control the
ordering of these -l arguments.  Therefore, we remove the FMS library
test in the ice-ocean and AM2-coupled build for the time being, and
explicitly set FMS in LIBS.

(We were already doing this in order to accommodate the other libraries,
but this raised issues in Nvidia, which objected to the double-linking
of FMS.  We now only set FMS linking in LIBS.)
  • Loading branch information
marshallward authored and adcroft committed Dec 14, 2023
1 parent e040565 commit 7e39fdf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
36 changes: 24 additions & 12 deletions ac/configure.mom6sis2.ac
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,30 @@ AX_FC_CHECK_MODULE([fms_mod], [], [
[-I${srcdir}/ac/deps/include])
])

# Test for fms_init to verify FMS library linking
AX_FC_CHECK_LIB([FMS], [fms_init], [fms_mod],
[], [
AS_UNSET([ax_fc_cv_lib_FMS_fms_init])
AX_FC_CHECK_LIB([FMS], [fms_init], [fms_mod], [
AC_SUBST([LDFLAGS], ["-L${srcdir}/ac/deps/lib $LDFLAGS"])
AC_SUBST([LIBS], ["-lFMS $LIBS"])
],
[AC_MSG_ERROR([Could not find FMS library.])],
[-L${srcdir}/ac/deps/lib])
]
)
# TODO: We cannot currently use this test, since it prepends -lFMS to LIBS.
# However, we need to append -lFMS, not prepend, since we are putting
# libraries in LIBS which depend on FMS, and some linkers can fail if in the
# wrong order (per POSIX convention).
#
# This could be resolved in a few different ways:
# * AX_FC_CHECK_LIB macros for each library
# * AX_FC_SEARCH_LIBS for FMS
# but there are issues with each of these options.
#
# For now, we remove the test and rely on LIBS, but should revisit this.
#
## Test for fms_init to verify FMS library linking
#AX_FC_CHECK_LIB([FMS], [fms_init], [fms_mod],
# [], [
# AS_UNSET([ax_fc_cv_lib_FMS_fms_init])
# AX_FC_CHECK_LIB([FMS], [fms_init], [fms_mod], [
# AC_SUBST([LDFLAGS], ["-L${srcdir}/ac/deps/lib $LDFLAGS"])
# AC_SUBST([LIBS], ["-lFMS $LIBS"])
# ],
# [AC_MSG_ERROR([Could not find FMS library.])],
# [-L${srcdir}/ac/deps/lib])
# ]
#)


# Verify that FMS is at least 2019.01.02
Expand Down
3 changes: 1 addition & 2 deletions coupled_AM2_LM3_SIS2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ MOM_LDFLAGS += $(LDFLAGS) \
-L$(abspath $(ICE_PARAM_BUILD)) \
-L$(abspath $(LM3_BUILD))

# TODO: Should be autodetected, but we'll get there...
# Also, appending -lFMS is a duplication but it needs to follow the others
# TODO: Should be generated by autoconf, but the macros need some fixing.
MOM_LIBS += -licebergs -lice_param -lLM3 -lAM2 -lFMS


Expand Down
3 changes: 1 addition & 2 deletions ice_ocean_SIS2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ MOM_LDFLAGS := $(LDFLAGS) \
-L$(abspath $(ATMOS_BUILD)) \
-L$(abspath $(LAND_BUILD))

# TODO: Should be autodetected, but we'll get there...
# Also, appending -lFMS is a duplication but it needs to follow the others
# TODO: Should be generated by autoconf, but the macros need some fixing.
MOM_LIBS += -licebergs -lice_param -latmos_null -lland_null -lFMS

# Autoconf variables
Expand Down

0 comments on commit 7e39fdf

Please sign in to comment.