https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358

            Bug ID: 81358
           Summary: libatomic not automatically linked with C11 code
           Product: gcc
           Version: 7.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: driver
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fxcoudert at gcc dot gnu.org
  Target Milestone: ---

This is on macOS 10.12 (Darwin 16.6.0). Compiling C11 code with -std=c11 fails
to link, unless one specifies -latomic

$ cat a.c
#include <stdio.h>
#include <complex.h>
#include <stdatomic.h>

int main(void)
{
    _Atomic long double _Complex x = 0.0 + 0.0*I;
    for (int i=0; i<1000; i++) {
        x += 1.0;
    }
    printf("(%Lf,%Lf)\n",creall(x), cimagl(x));
    printf("%zu\n",sizeof(x));
    return 0;
}

$ gcc-7 -std=c11 a.c -latomic
$ gcc-7 -std=c11 a.c         
Undefined symbols for architecture x86_64:
  "___atomic_feraiseexcept", referenced from:
      _main in cceeEpua.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status


------

>From Homebrew report at https://github.com/Homebrew/homebrew-core/issues/14633

$ gcc-7 -v
Using built-in specs.
COLLECT_GCC=gcc-7
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/7.1.0/libexec/gcc/x86_64-apple-darwin16.6.0/7.1.0/lto-wrapper
Target: x86_64-apple-darwin16.6.0
Configured with: ../configure --build=x86_64-apple-darwin16.6.0
--prefix=/usr/local/Cellar/gcc/7.1.0
--libdir=/usr/local/Cellar/gcc/7.1.0/lib/gcc/7
--enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-7
--with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr
--with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl
--with-system-zlib --enable-checking=release --with-pkgversion='Homebrew GCC
7.1.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues
--disable-nls --with-native-system-header-dir=/usr/include
--with-sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
Thread model: posix
gcc version 7.1.0 (Homebrew GCC 7.1.0)

Reply via email to