Closed crisluengo closed 5 years ago
From the issue template:
Please note we will close your issue without comment if you delete, do not read or do not fill out the issue checklist below and provide ALL the requested information. If you repeatedly fail to use the issue template, we will block you from ever submitting issues to Homebrew again.
If you add the necessary information to this issue (don't create a new one, please) then this issue may be reopened.
Is there no way to get this issue reopened?
GCC should never include any directory in front of its own standard library directories. In particular, the search order seems to be:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/stdlib.h
/usr/local/Cellar/gcc/9.1.0/include/c++/9.1.0/stdlib.h
but this should be the other way around.
Pull requests would be appreciated but there simply aren't enough maintainers of homebrew to maintain beta versions of macOS/apple tools. If you install an unsupported version you're on your own.
@SMillerDev I understand that you guys are stretched thin. However, this was a normal upgrade suggested by my OS, how am I supposed to know it is an unsupported version?
I'm trying to figure out what is going on. It seems that GCC depends on the system's C library, so this is intended behaviour. It is a change to the system's C library that is not compatible with GCC.
This is a bug in the C library that comes with the updated Xcode. To fix it, edit the file /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/Availability.h
(must be done as root). Near the point where the error is generated (line number 257), add the following two lines:
#elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) #if defined(__has_builtin) // <=== ADD THIS LINE #if __has_builtin(__is_target_arch) #if __has_builtin(__is_target_vendor) #if __has_builtin(__is_target_os) #if __has_builtin(__is_target_environment) #if __has_builtin(__is_target_variant_os) #if __has_builtin(__is_target_variant_environment) #if (__is_target_arch(x86_64) && __is_target_vendor(apple) && ((__is_target_os(ios) && __is_target_environment(macabi)) || (__is_target_variant_os(ios) && __is_target_variant_environment(macabi)))) #define __OSX_AVAILABLE_STARTING(_osx, _ios) __AVAILABILITY_INTERNAL##_osx __AVAILABILITY_INTERNAL##_ios #define __OSX_AVAILABLE_BUT_DEPRECATED(_osxIntro, _osxDep, _iosIntro, _iosDep) \ __AVAILABILITY_INTERNAL##_osxIntro##_DEP##_osxDep __AVAILABILITY_INTERNAL##_iosIntro##_DEP##_iosDep #define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg) \ __AVAILABILITY_INTERNAL##_osxIntro##_DEP##_osxDep##_MSG(_msg) __AVAILABILITY_INTERNAL##_iosIntro##_DEP##_iosDep##_MSG(_msg) #endif /* # if __is_target_arch... */ #endif /* #if __has_builtin(__is_target_variant_environment) */ #endif /* #if __has_builtin(__is_target_variant_os) */ #endif /* #if __has_builtin(__is_target_environment) */ #endif /* #if __has_builtin(__is_target_os) */ #endif /* #if __has_builtin(__is_target_vendor) */ #endif /* #if __has_builtin(__is_target_arch) */ #endif // <=== ADD THIS LINE #ifndef __OSX_AVAILABLE_STARTING #define __OSX_AVAILABLE_STARTING(_osx, _ios) __AVAILABILITY_INTERNAL##_osx #define __OSX_AVAILABLE_BUT_DEPRECATED(_osxIntro, _osxDep, _iosIntro, _iosDep) \ __AVAILABILITY_INTERNAL##_osxIntro##_DEP##_osxDep #define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg) \ __AVAILABILITY_INTERNAL##_osxIntro##_DEP##_osxDep##_MSG(_msg) #endif /* __OSX_AVAILABLE_STARTING */ #else
Needless to say, edit system files at your own risk! :)
@crisluengo unfortunately the issue persists for me even after making that change. I'm on macOS 10.15 though and made the above suggested edit in the 10.15 SDK instead of the 10.14 SDK. I've been debugging this since Monday and was hoping this was the solution. Frustrating :(
this was a normal upgrade suggested by my OS, how am I supposed to know it is an unsupported version?
Xcode 11 is beta, so this was not a “normal” update, or you've configured at some point your system to install beta versions (and likely forgotten about it 😄).
GCC should never include any directory in front of its own standard library directories
This is not the issue.
It is a change to the system's C library that is not compatible with GCC
Yes. The beta SDK includes in Availability.h
some code that is not standard C compliant, because it uses the clang-specific __has_builtin
built-in unconditionally. Please report this to Apple so they can get it fixed.
sys/cdefs.h
defines __has_builtin
and others if they're not available. Including sys/cdefs.h
before stdlib.h
fixes the problem.
Including sys/cdefs.h before stdlib.h fixes the problem
There are many such workarounds. The only real fix is to report the problem to Apple, so they can fix it. (Duplicate reports actually help them determine what is a pressing issue, too.)
@crisluengo It fixes my problem, I just updated yesterday. Thanks bro.
This same issue happens for me in Xcode 10.2.1. @crisluengo's solution of ordering import paths properly makes the most sense to me. I was able to ditch homebrew's gcc and use clang but wanted to "+1" this post.
TL;DR I faced the same issue and configure CPPFLAGS='-D__has_builtin(x)=0' ...
was my workaround ([EDIT] that was good enough to pass configure
but crashed at make
time)
On my up-to-date (OS X and brew) Mac (with zero beta software) I tried to build Open MPI and configure
failed with the following error message
ptrdiff_t type is not available, this is required by C99 standard. Cannot continue
after some debugging, I found that this autoconf
test failed
checking for ANSI C header files... no
and this is caused by the issue discussed here.
Though it is technically correct to blame Apple for breaking stdlib.h
, or even Open MPI for expecting autoconf
will #include <stddef.h>
under the hood, I am afraid this issue has a much larger impact that some might have expected.
I do not know the policy (if any) for dealing with such cases, but IMHO, a workaround should be included in the brew package in order to be (even) more user friendly.
my 0.02US$
I see this with Xcode Version 10.2.1 (10E1001) but find that I can resolve it by switching
#include <stdlib.h>
#include <stdio.h>
to
#include <stdio.h>
#include <stdlib.h>
This solution exists because stdio.h
causes the definition of __has_builtin
.
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include//secure/_stdio.h:#ifndef __has_builtin
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include//secure/_stdio.h:#define _undef__has_builtin
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include//secure/_stdio.h:#define __has_builtin(x) 0
I got lucky in finding this one because I always insist on including <stdio.h>
before all the other <st*.h>
, for what has been, until now, nothing more than aesthetics.
FWIW, based on @jeffhammond workaround, I made the patch below for autoconf so stdio.h
is always included before stdlib.h
is used.
Though the patch itself should not fix anything, it is harmless and good enough (for now) to work around the broken headers.
@MikeMcQuaid FYI
in order to apply it, simply add the following lines in the autoconf
formula
patch do
url "https://gist.githubusercontent.com/ggouaillardet/11e15a9349dc2100d98d59a5ccc3c74e/raw/34e16d46fd1f1f5cc060d15afbb3c94a385ebdcb/autoconf.diff"
sha256 "7c415d8994fa668dc16803950c0b3e92ad8f400fbf5a7adc0f6ea59fe29a3640"
end
diff -ruN orig/autoconf-2.69/lib/autoconf/c.m4 autoconf-2.69/lib/autoconf/c.m4
--- orig/autoconf-2.69/lib/autoconf/c.m4 2012-01-21 22:46:39.000000000 +0900
+++ autoconf-2.69/lib/autoconf/c.m4 2019-07-22 17:01:36.000000000 +0900
@@ -1204,11 +1204,11 @@
# variable length arrays.
AC_DEFUN([_AC_PROG_CC_C99],
[_AC_C_STD_TRY([c99],
-[[#include <stdarg.h>
+[[#include <stdio.h>
+#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>
#include <wchar.h>
-#include <stdio.h>
// Check varargs macros. These examples are taken from C99 6.10.3.5.
#define debug(...) fprintf (stderr, __VA_ARGS__)
@@ -1849,8 +1849,8 @@
ac_cv_c_flexmember,
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
- [[#include <stdlib.h>
- #include <stdio.h>
+ [[#include <stdio.h>
+ #include <stdlib.h>
#include <stddef.h>
struct s { int n; double d[]; };]],
[[int m = getchar ();
diff -ruN orig/autoconf-2.69/lib/autoconf/functions.m4 autoconf-2.69/lib/autoconf/functions.m4
--- orig/autoconf-2.69/lib/autoconf/functions.m4 2012-01-21 22:46:39.000000000 +0900
+++ autoconf-2.69/lib/autoconf/functions.m4 2019-07-22 17:03:44.000000000 +0900
@@ -890,7 +890,8 @@
AC_CACHE_CHECK([for GNU libc compatible malloc], ac_cv_func_malloc_0_nonnull,
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
-[[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
+[[#include <stdio.h>
+#if defined STDC_HEADERS || defined HAVE_STDLIB_H
# include <stdlib.h>
#else
char *malloc ();
@@ -1003,6 +1004,7 @@
#endif
#include <limits.h>
+#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
@@ -1395,7 +1397,8 @@
AC_CACHE_CHECK([for GNU libc compatible realloc], ac_cv_func_realloc_0_nonnull,
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
-[[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
+[[#include <stdio.h>
+#if defined STDC_HEADERS || defined HAVE_STDLIB_H
# include <stdlib.h>
#else
char *realloc ();
@@ -1595,6 +1598,7 @@
[[/* On HP-UX before 11.23, strtold returns a struct instead of
long double. Reject implementations like that, by requiring
compatibility with the C99 prototype. */
+# include <stdio.h>
# include <stdlib.h>
static long double (*p) (char const *, char **) = strtold;
static long double
diff -ruN orig/autoconf-2.69/lib/autoconf/headers.m4 autoconf-2.69/lib/autoconf/headers.m4
--- orig/autoconf-2.69/lib/autoconf/headers.m4 2012-04-25 11:37:26.000000000 +0900
+++ autoconf-2.69/lib/autoconf/headers.m4 2019-07-22 17:02:16.000000000 +0900
@@ -676,7 +676,8 @@
# --------------
AC_DEFUN([AC_HEADER_STDC],
[AC_CACHE_CHECK(for ANSI C header files, ac_cv_header_stdc,
-[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
+#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <float.h>
@@ -697,7 +698,8 @@
if test $ac_cv_header_stdc = yes; then
# /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
AC_RUN_IFELSE([AC_LANG_SOURCE(
-[[#include <ctype.h>
+[[#include <stdio.h>
+#include <ctype.h>
#include <stdlib.h>
#if ((' ' & 0x0FF) == 0x020)
# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
Thanks for the work but I'm just gonna repeat what fx said cause it's essential in this:
There are many such workarounds. The only real fix is to report the problem to Apple, so they can fix it. (Duplicate reports actually help them determine what is a pressing issue, too.)
One can dismiss essentially all good engineering solutions by identifying better ones.
https://en.wikipedia.org/wiki/Perfect_is_the_enemy_of_good
@jeffhammond Your meta-commentary is not welcome or necessary, thanks.
I just upgraded the Xcode Command Line Tools to 11.0. Now I can no longer compile with GCC 9. I get this error with any C++ file that includes
cstdlib
:It looks like
cstdlib
includesstdlib.h
, but GCC finds it among Clang's header files, rather than the ones that come with GCC. This version ofstdlib.h
uses some compiler intrinsic that is unique to Clang.This is the output of
gcc --version
:Homebrew is up to date and I have the latest GCC installed through Homebrew.
I have uninstalled GCC and installed it anew, with no change in behavior.
Related issues: 1, 2
brew install
(orupgrade
,reinstall
) a single, Homebrew/homebrew-core formula (not cask) on macOS? If it's a generalbrew
problem please file this issue at Homebrew/brew: https://github.com/Homebrew/brew/issues/new/choose. If it's a Linux problem please file this issue at https://github.com/Homebrew/linuxbrew-core/issues/new/choose. If it's abrew cask
problem please file this issue at https://github.com/Homebrew/homebrew-cask/issues/new/choose. If it's a tap (e.g. Homebrew/homebrew-php) problem please file this issue at the tap.brew update
and can still reproduce the problem?brew doctor
, fixed all issues and can still reproduce the problem?brew gist-logs <formula>
(where<formula>
is the name of the formula that failed) and included the output link?brew gist-logs
didn't work: ranbrew config
andbrew doctor
and included their output with your issue?