CCTK_CHECK_HEADER_LIB_FUNC adds library multiple times to $LIBS

Issue #1334 new
Frank Löffler created an issue

CCTK_CHECK_HEADER_LIB_FUNC (in aclocal.m4) adds its second argument to $LIBS, every time it is called. I found 8 invocations in configure.in, each time adding the math library, resulting in a very weird (but not necessarily wrong) link line in Cactus.

I am not entirely sure about what to do here, but my best guess is that $LIBS shouldn't be changed at all after this function was called. An alternative would be to check for the existance of $2 in $LIBS before it is unconditionally added.

Keyword:

Comments (3)

  1. Roland Haas

    As @Frank Löffler mentions, adding a library multiple times is harmless. Sometimes, for static linking, it is even required if there are two libraries that require functions from each other.

    Eg. libA contains funcA1 and funcA2. funcA1 calls funcB1 in libB which itself calls funcA2 in libA. The way to link these correctly for static linking is -lA -lB -lA that is one has to repeat one (or the other) of the libraries since the linker acts on the library list only once and does so sequentially and will only include objects from a library that if it already knows that the object is required when it processes the library file.

    This may not be an issue for CCTK_CHECK_HEADER_LIB_FUNC if it only ever uses a single library, but would be an issue if it ever added two libraries since -lA -lB -lA -lB is not the same as -lA -lB.

  2. Roland Haas

    One could try and beautify the library list by removing consecutive identical libraries m m m or similar, which may help a bit but is not guaranteed to remove all possible redundant duplicates.

  3. Log in to comment