6

After updating to Mojave 10.14.4 and Xcode 10.2, I fail to compile GCC 8.3.0. The error message is

In file included from /usr/include/sys/sysctl.h:83,
                 from ../../gcc-8.3.0/gcc/config/darwin-driver.c:30:
/usr/include/sys/ucred.h:94:2: error: ‘_Atomic’ does not name a type
  _Atomic u_long          cr_ref;  /* reference count */
  ^~~~~~~

I have not found any clue how this can be fixed. The header in question is

struct ucred {
    LIST_ENTRY(ucred)       cr_link; /* never modify this without KAUTH_CRED_HASH_LOCK */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
    _Atomic u_long          cr_ref;  /* reference count */
#elif defined(__cplusplus) && __cplusplus >= 201103L
    _Atomic u_long          cr_ref;  /* reference count */   // <--- this line
#else
    volatile u_long         cr_ref;  /* reference count */
#endif

Any ideas are highly appreciated!

  • I was in the process of writing an answer for you when this was put on hold: "You need to use a C11 compatible compiler in order to have support for the _Atomic keyword. Ensure that you are compiling with a recent, modern compiler, and that STDC_NO_ATOMICS is not defined. " – jksoegaard Mar 28 at 11:01
  • 1
    @nohillside This is not a software development question. It is a user trying to install GCC 8.3.0 by compiling the software - not a user trying to develop new software. – jksoegaard Mar 28 at 11:02
  • How are you compiling gcc. Easiest way is to use macports or homebrew. If you do not want to do that then at least see how they got the compile to work. – user151019 Mar 28 at 11:12
  • @jksoegaard Thanks, please post your answer – nohillside Mar 28 at 11:43
  • I have a similar problem. I am not able to compile a program using the GNU G++ 7 from MacPorts, when including the tbb/parallel_sort.h. It prints the exact same error message, but my trace goies to Xcode /usr/include/sys/sysctl.h. – fcdimitr Mar 28 at 18:10
5

I encountered the same problem myself. The error is actually reported by g++, a C++ compiler. On MacOS 10.14.4, the header file <sys/ucred.h> uses the _Atomic keyword for C++, although it is only defined in the C standard. (I assume that Apple's compiler clang++ defines this keyword as extension to the C++ standard.)

The proper fix is to tell gcc to "fixinclude" the header file <sys/ucred.h>. This patch does this. This is a patch that needs to be applied to the source code of GCC 8.3.0 before building it.

  • Thanks a lot, this fixes the build! If the same trick is also done in the sanitizer's code, I could also build GCC from trunk. – Niels Lohmann Mar 29 at 11:39
1

You need to use a C11 compatible compiler in order to have support for the _Atomic keyword.

Ensure that you are compiling with a recent, modern compiler, and that STDC_NO_ATOMICS is not defined.

It might be easier for you to use HomeBrew in order to compile it without having to configure anything yourself. After installing HomeBrew, you can install gcc with:

brew install gcc
  • I am using Apple LLVM version 10.0.1 (clang-1001.0.46.3) which should be C11 compatible. It does not define STDC_NO_ATOMICS. – Niels Lohmann Mar 28 at 13:08
  • I do want to compile GCC myself, because the latest versions are not always available on Homebrew. Furthermore, this used to work, and I would like to fix this :) – Niels Lohmann Mar 28 at 13:09
  • I'm encountering this same issue as OP and homebrew fails with the same error. – mrfred Apr 4 at 17:11
-1

I had the same issue and I found a solution here.

macOS Mojave changed the location of the system headers, this broke the GCC 8 build process. In order to build GCC install the required header files in the old location:

The solution is to install the package found in the following directory.

/Library/Developer/CommandLineTools/Packages/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .