Best practice for linking against libatomic?
Simon Richter
Simon.Richter@hogyros.de
Tue Jan 13 00:58:51 GMT 2026
Hi,
On 1/12/26 11:59 PM, Florian Weimer wrote:
> It would be interesting to know which functionality needs libatomic.
> What are the linker errors you encountered?
Missing symbols, the ones in the build logs I have are:
- __atomic_exchange_1
- __atomic_fetch_add_2
- __atomic_compare_exchange_1
There are a few weird ones, like
/usr/bin/ld: /tmp/ccXOVIUZ.ltrans0.ltrans.o: undefined reference to
symbol '__atomic_exchange_1@@LIBATOMIC_1.0'
so for LTO, there seems to be an error path that can find the version,
but then does not resolve the symbol -- these are fairly seldom though.
With gcc 16 making this change automatic, I suspect a lot of failures
will go away, I'm not sure if that is portable though, or if a configure
script is supposed to find out if libatomic needs to be linked, which
some seem to do with varying degrees of success.
I mean, would it make sense to build an autoconf macro like
"AC_LIB_ATOMIC([bool, int, void *])" that would determine if making any
of the listed types atomic requires linking against libatomic?
Simon
More information about the Gcc-help
mailing list