Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error building with gcc using Xcode 11 when including algorithm header #44579

Closed
3 of 6 tasks
rrahn opened this issue Sep 25, 2019 · 11 comments
Closed
3 of 6 tasks

Error building with gcc using Xcode 11 when including algorithm header #44579

rrahn opened this issue Sep 25, 2019 · 11 comments
Labels
10.15 Catalina is specifically affected outdated PR was locked due to age

Comments

@rrahn
Copy link

rrahn commented Sep 25, 2019

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.

To help us debug your issue please explain:

  • What you were trying to do (and why)

I updated my xcode to the newest version Xcode 11 on macos 10.14.6. I reinstalled all my productive gcc's (7, 8, 9). If I try to compile the following snippet:

#include <algorithm>

int main()
{
   return 0;
}

with the following compiler falgs:

g++-7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -mmacosx-version-min=10.14 -c test.cpp
  • What happened (include command output)

it fails with the following errors.

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/wait.h:110:0,
                 from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h:66,
                 from /usr/local/Cellar/gcc@7/7.4.0_2/include/c++/7.4.0/cstdlib:75,
                 from /usr/local/Cellar/gcc@7/7.4.0_2/include/c++/7.4.0/bits/stl_algo.h:59,
                 from /usr/local/Cellar/gcc@7/7.4.0_2/include/c++/7.4.0/algorithm:62,
                 from test.cpp:2:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/resource.h:443:34: error: expected initializer before '__OSX_AVAILABLE_STARTING'
 int     getiopolicy_np(int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
                                  ^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/resource.h:449:39: error: expected initializer before '__OSX_AVAILABLE_STARTING'
 int     setiopolicy_np(int, int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
                                       ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h:128:0,
                 from /usr/local/Cellar/gcc@7/7.4.0_2/include/c++/7.4.0/cstdlib:75,
                 from /usr/local/Cellar/gcc@7/7.4.0_2/include/c++/7.4.0/bits/stl_algo.h:59,
                 from /usr/local/Cellar/gcc@7/7.4.0_2/include/c++/7.4.0/algorithm:62,
                 from test.cpp:2:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/malloc/_malloc.h:52:74: error: expected initializer before '__OSX_AVAILABLE_STARTING'
 int   posix_memalign(void **__memptr, size_t __alignment, size_t __size) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_0);
                                                                          ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc@7/7.4.0_2/include/c++/7.4.0/cstdlib:75:0,
                 from /usr/local/Cellar/gcc@7/7.4.0_2/include/c++/7.4.0/bits/stl_algo.h:59,
                 from /usr/local/Cellar/gcc@7/7.4.0_2/include/c++/7.4.0/algorithm:62,
                 from test.cpp:2:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h:270:53: error: expected initializer before '__OSX_AVAILABLE_STARTING'
 void  arc4random_buf(void * __buf, size_t __nbytes) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
                                                     ^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h:273:46: error: expected initializer before '__OSX_AVAILABLE_STARTING'
   arc4random_uniform(uint32_t __upper_bound) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
                                              ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc@7/7.4.0_2/include/c++/7.4.0/cstdlib:75:0,
                 from /usr/local/Cellar/gcc@7/7.4.0_2/include/c++/7.4.0/bits/stl_algo.h:59,
                 from /usr/local/Cellar/gcc@7/7.4.0_2/include/c++/7.4.0/algorithm:62,
                 from test.cpp:2:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h:292:45: error: expected initializer before '__OSX_AVAILABLE_BUT_DEPRECATED_MSG'
 int  daemon(int, int) __DARWIN_1050(daemon) __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_0, __MAC_10_5, __IPHONE_2_0, __IPHONE_2_0, "Use posix_spawn APIs instead.") __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h:325:6: error: expected initializer before '__OSX_AVAILABLE_STARTING'
      __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
      ^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h:333:6: error: expected initializer before '__OSX_AVAILABLE_STARTING'
      __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
  • What you expected to happen

I would have expected no error, since it seems like messed up include orders.
In fact when including e.g. string before algorithm the code compiles just fine:

#include <string>
#include <algorithm>

int main()
{
   return 0;
}
  • Step-by-step reproduction instructions (by running brew install commands)

install latest xcode 11 on macos 10.14 or macos 10.15
optionally upgrade gcc
compile the above code with:

g++-7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -mmacosx-version-min=10.14 -c test.cpp

Note the isysroot and macsox-version-min are set by cmake automatically. If one removes these the code compiles as well.
I am also not very sure if this is the right place for this issue or if this should be fixed upstream by apple. Maybe, I am also just getting something completely wrong, but since it depends on the includes of the file I guess something unusal is broken. Any advice or assistance is very appreciated.

@rrahn rrahn changed the title Error building with gcc with xcode 11 when including algorithm header Error building with gcc using Xcode 11 when including algorithm header Sep 25, 2019
@rrahn
Copy link
Author

rrahn commented Oct 8, 2019

Here is the output of gist-log:

~/D/s/s/u/r/decorator $ brew gist-logs gcc
Error: No logs.
~/D/s/s/u/r/decorator $ brew gist-logs gcc@8
Error: No logs.
~/D/s/s/u/r/decorator $ brew gist-logs gcc@7
Error: No logs.

Here is the output of brew doctor if it helps:

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and which additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew-provided
script of the same name. We found the following "config" scripts:
  /opt/local/bin/libpng16-config
  /opt/local/bin/python2.7-config
  /opt/local/bin/libpng-config
  /opt/local/bin/xml2-config
  /opt/local/bin/curl-config
  /Applications/Xcode.app/Contents/Developer/usr/bin/python3.7-config
  /Applications/Xcode.app/Contents/Developer/usr/bin/python3.7m-config
  /Applications/Xcode.app/Contents/Developer/usr/bin/python3-config

Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected header files:
  /usr/local/include/benchmark/benchmark.h
  /usr/local/include/gmock/gmock-actions.h
  /usr/local/include/gmock/gmock-cardinalities.h
  /usr/local/include/gmock/gmock-generated-actions.h
  /usr/local/include/gmock/gmock-generated-function-mockers.h
  /usr/local/include/gmock/gmock-generated-matchers.h
  /usr/local/include/gmock/gmock-generated-nice-strict.h
  /usr/local/include/gmock/gmock-matchers.h
  /usr/local/include/gmock/gmock-more-actions.h
  /usr/local/include/gmock/gmock-more-matchers.h
  /usr/local/include/gmock/gmock-spec-builders.h
  /usr/local/include/gmock/gmock.h
  /usr/local/include/gmock/internal/custom/gmock-generated-actions.h
  /usr/local/include/gmock/internal/custom/gmock-matchers.h
  /usr/local/include/gmock/internal/custom/gmock-port.h
  /usr/local/include/gmock/internal/gmock-generated-internal-utils.h
  /usr/local/include/gmock/internal/gmock-internal-utils.h
  /usr/local/include/gmock/internal/gmock-port.h
  /usr/local/include/gtest/gtest-death-test.h
  /usr/local/include/gtest/gtest-message.h
  /usr/local/include/gtest/gtest-param-test.h
  /usr/local/include/gtest/gtest-printers.h
  /usr/local/include/gtest/gtest-spi.h
  /usr/local/include/gtest/gtest-test-part.h
  /usr/local/include/gtest/gtest-typed-test.h
  /usr/local/include/gtest/gtest.h
  /usr/local/include/gtest/gtest_pred_impl.h
  /usr/local/include/gtest/gtest_prod.h
  /usr/local/include/gtest/internal/custom/gtest-port.h
  /usr/local/include/gtest/internal/custom/gtest-printers.h
  /usr/local/include/gtest/internal/custom/gtest.h
  /usr/local/include/gtest/internal/gtest-death-test-internal.h
  /usr/local/include/gtest/internal/gtest-filepath.h
  /usr/local/include/gtest/internal/gtest-internal.h
  /usr/local/include/gtest/internal/gtest-linked_ptr.h
  /usr/local/include/gtest/internal/gtest-param-util-generated.h
  /usr/local/include/gtest/internal/gtest-param-util.h
  /usr/local/include/gtest/internal/gtest-port-arch.h
  /usr/local/include/gtest/internal/gtest-port.h
  /usr/local/include/gtest/internal/gtest-string.h
  /usr/local/include/gtest/internal/gtest-tuple.h
  /usr/local/include/gtest/internal/gtest-type-util.h

Warning: Unbrewed .pc files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected .pc files:
  /usr/local/lib/pkgconfig/benchmark.pc
  /usr/local/lib/pkgconfig/gmock.pc
  /usr/local/lib/pkgconfig/gmock_main.pc
  /usr/local/lib/pkgconfig/gtest.pc
  /usr/local/lib/pkgconfig/gtest_main.pc

Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected static libraries:
  /usr/local/lib/libbenchmark.a
  /usr/local/lib/libbenchmark_main.a
  /usr/local/lib/libgmock.a
  /usr/local/lib/libgmock_main.a
  /usr/local/lib/libgtest.a
  /usr/local/lib/libgtest_main.a

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  mono

Warning: Homebrew's sbin was not found in your PATH but you have installed
formulae that put executables in /usr/local/sbin.
Consider setting the PATH for example like so:
  echo 'set -g fish_user_paths "/usr/local/sbin" $fish_user_paths' >> ~/.config/fish/config.fish

I know, this should be clean but it is mostly just gtest and gbench related stuff. So I think it should not be related to the issue. I see that I remove these and give an update if this should fix things.

I also reference #44776 which seems to be the place to gather catalina issues. But note that it seems to be related to Xcode 11 and not catalina per sé.

@fxcoudert
Copy link
Member

fxcoudert commented Oct 9, 2019

The 10.15 SDK headers in Xcode 11 have a bug in them. It was reported to Apple as FB7338312 (Availability.h is not C-compliant).

I've added a local patch to the main GCC formula (see #44762) so that it should build fine now. Can you check? (with the latest version, not older versions)

@fxcoudert fxcoudert added the 10.15 Catalina is specifically affected label Oct 9, 2019
@enigmata
Copy link

@fxcoudert Verified the local patch works for me. I had the same problem as OP, where I first saw it on Mojave and then carried through to Catalina. I forced a brew reinstall of gcc to get the patch (gcc-9.2.0_1.catalina.bottle) and now it builds clean.

Thx so much!

@rrahn
Copy link
Author

rrahn commented Oct 10, 2019

Hi, thanks for the effort. I am wondering if I am doing something wrong. I did verify that I have the current patch as suggested by looking at the gcc formula (brew edit gcc). I did perform a brew reinstall of gcc and also via -s flag. In both versions the error persists in my code base. I am truly sorry if I am missing something obvious and any help is very appreciated.

@fxcoudert
Copy link
Member

After reinstalling, do you have a file named /usr/local/Cellar/gcc/9.2.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.2.0/include-fixed/Availability.h?

@rrahn
Copy link
Author

rrahn commented Oct 11, 2019

Something similar:
/usr/local/Cellar/gcc/9.2.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.2.0/include-fixed/AvailabilityInternal.h Is that it?

@fxcoudert
Copy link
Member

No, it should have a Availability.h in addition to AvailabilityInternal.h.

Can you paste the output of brew config?

@rrahn
Copy link
Author

rrahn commented Oct 11, 2019

Sure. Here it is:

brew config
HOMEBREW_VERSION: 2.1.13
ORIGIN: https://github.com/Homebrew/brew
HEAD: aa043c1d678afd26f50156a83417c296cb9d5a4b
Last commit: 3 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 36584b326e232b849dfbce110d8e9ce5c54632df
Core tap last commit: 2 days ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_DEV_CMD_RUN: 1
CPU: octa-core 64-bit skylake
Homebrew Ruby: 2.3.7 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Clang: 11.0 build 1100
Git: 2.21.0 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 7.54.0 => /usr/bin/curl
Java: 1.8.0_202, 1.8.0_192, 1.8.0_181, 1.8.0_172, 1.8.0_162, 1.8.0_152, 1.8.0_144, 1.8.0_141, 1.8.0_131, 1.8.0_121
macOS: 10.14.6-x86_64
CLT: 10.3.0.0.1.1562985497
Xcode: 11.0
CLT headers: 10.3.0.0.1.1562985497
XQuartz: 2.7.11 => /opt/X11

@fxcoudert
Copy link
Member

@rrahn I think the issue might be because of the mismatch between your Xcode and CLT versions

@rrahn
Copy link
Author

rrahn commented Oct 11, 2019

@fxcoudert yes!!! Many thanks for the great support. Updating the command line tools and reinstalling gcc from source indeed fixed it for me. Is there any chance this patch can be back ported for gcc@8 and gcc@7?

@fxcoudert
Copy link
Member

Will do it at some point, after reporting it to GCC as well

@rrahn rrahn closed this as completed Oct 12, 2019
rfabbri added a commit to rfabbri/openMVG that referenced this issue Oct 25, 2019
This is only an attempt that might work because OpenMVG travis only tasts Xcode < 11 at the present date.
Latest Xcode 11 currently has bugs with GCC which prevents for
compiling. These are the curent errors with Xcode 11, which will be fixed soon upstream
see Homebrew/homebrew-core#44579

[  0%] Building CXX object dependencies/osi_clp/CoinUtils/src/CMakeFiles/lib_CoinUtils.dir/CoinBuild.cpp.o
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/wait.h:110,
                 from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h:66,
                 from /usr/local/Cellar/gcc/9.2.0_1/include/c++/9.2.0/cstdlib:75,
                 from /Users/rfabbri/cprg/vxlprg/lemsvpe/openMVG/src/dependencies/osi_clp/CoinUtils/src/CoinBuild.cpp:7:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/resource.h:443:34: error: expected initializer before '__OSX_AVAILABLE_STARTING'
  443 | int     getiopolicy_np(int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/resource.h:449:39: error: expected initializer before '__OSX_AVAILABLE_STARTING'
  449 | int     setiopolicy_np(int, int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
@lock lock bot added the outdated PR was locked due to age label Jan 1, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
10.15 Catalina is specifically affected outdated PR was locked due to age
Projects
None yet
Development

No branches or pull requests

3 participants