Skip to content

Unable to find libc installation: system C compiler exited with failure code #4521

Closed

Description

@SeekingMeaning

Running brew install zig --HEAD produces the error Unable to find libc installation: system C compiler exited with failure code

Log: https://gist.github.com/SeekingMeaning/d27a6a7285565897ebbd9eefce86e796

A hacky fix I found was to make this change to the zig formula:

   def install
+    if build.head?
+        ENV["CC"] = Formula["llvm"].opt_bin/"clang"
+    end
     system "cmake", ".", *std_cmake_args
     system "make", "install"
   end

Activity

  1. andrewrk commented on Feb 22, 2020

    @andrewrk
    Member

    What does this command do on your system?

    cc -E -Wp,-v -xc /dev/null

  2. SeekingMeaning commented on Feb 22, 2020

    @SeekingMeaning
    Author
    clang -cc1 version 11.0.0 (clang-1100.0.33.17) default target x86_64-apple-darwin19.3.0
    ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
    ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
    #include "..." search starts here:
    #include <...> search starts here:
     /usr/local/include
     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
    End of search list.
    # 1 "/dev/null"
    # 1 "<built-in>" 1
    # 1 "<built-in>" 3
    # 362 "<built-in>" 3
    # 1 "<command line>" 1
    # 1 "<built-in>" 2
    # 1 "/dev/null" 2
    
  3. andrewrk commented on Feb 22, 2020

    @andrewrk
    Member

    That looks correct. That's the command zig runs that is failing. More investigation is needed to diagnose this

  4. SeekingMeaning commented on Feb 22, 2020

    @SeekingMeaning
    Author

    Not sure if this helps, but here's the output for /usr/local/opt/llvm/bin/clang -E -Wp,-v -xc /dev/null:

    clang -cc1 version 9.0.1 based upon LLVM 9.0.1 default target x86_64-apple-darwin19.3.0
    ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
    ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
    #include "..." search starts here:
    #include <...> search starts here:
     /usr/local/Cellar/llvm/9.0.1/lib/clang/9.0.1/include
     /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
     /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
    End of search list.
    # 1 "/dev/null"
    # 1 "<built-in>" 1
    # 1 "<built-in>" 3
    # 352 "<built-in>" 3
    # 1 "<command line>" 1
    # 1 "<built-in>" 2
    # 1 "/dev/null" 2
    
  5. andrewrk commented on Feb 22, 2020

    @andrewrk
    Member

    Thanks. I'll update the native libc detection to output more helpful diagnostics if the system C compiler exits with a failure code.

  6. andrewrk commented on Feb 22, 2020

    @andrewrk
    Member

    I am able to reproduce this with brew install zig --HEAD on my machine.

  7. zbeekman commented on Feb 22, 2020

    @zbeekman

    The output of cc -E -Wp,-v -xc /dev/null the the formula would see during building from source is different and can be found by first executing: brew install --HEAD --fetch-HEAD --interactive zig. This will drop you into a shell with the zig sources present with the same environment that Homebrew uses to build zig.

    Due to the dependency on llvm (and then it's transitive dependencies) the chief difference is in the search path.

    $ cc -E -Wp,-v -xc /dev/null
    clang -cc1 version 11.0.0 (clang-1100.0.33.17) default target x86_64-apple-darwin18.7.0
    ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/local/include"
    ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/Library/Frameworks"
    #include "..." search starts here:
    #include <...> search starts here:
     /usr/local/opt/llvm/include
     /usr/local/include
     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/libxml2
     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers
     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include
     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks (framework directory)
    End of search list.
    # 1 "/dev/null"
    # 1 "<built-in>" 1
    # 1 "<built-in>" 3
    # 362 "<built-in>" 3
    # 1 "<command line>" 1
    # 1 "<built-in>" 2
    # 1 "/dev/null" 2
    

    Note that, due to the llvm dependency in the formula (is this needed?) /usr/local/opt/llvm/include is the first system search path.

    In addition these CMake variables get set in the build environment and may play a role in determining where CMake finds stuff:

    $ env | grep -i cmake
    HOMEBREW_DEPENDENCIES=cmake,libffi,pcre,swig,llvm
    CMAKE_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/libxml2:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers
    CMAKE_PREFIX_PATH=/usr/local/opt/libffi:/usr/local/opt/llvm:/usr/local
    PATH=/Users/ibeekman/.wasmer/bin:/usr/local/Cellar/modules/4.4.1/bin:/usr/local/Homebrew/Library/Homebrew/shims/mac/super:/usr/local/opt/cmake/bin:/usr/local/opt/pcre/bin:/usr/local/opt/swig/bin:/usr/local/opt/llvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/fzf/bin:/Users/ibeekman/.wasmer/globals/wapm_packages/.bin
    CMAKE_LIBRARY_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries
    
  8. added
    bug
    on Feb 22, 2020
  9. added this to the 0.6.0 milestone on Feb 22, 2020
  10. andrewrk commented on Feb 22, 2020

    @andrewrk
    Member

    @zbeekman thanks for the tip. Although I'm able to reproduce the issue with brew install zig --HEAD, when I build zig manually inside the interactive shell with brew install --HEAD --fetch-HEAD --interactive zig, I am not able to reproduce the issue.

  11. andrewrk commented on Feb 22, 2020

    @andrewrk
    Member

    Here's a new clue after 0cd89e9:

    Zig attempted to find the path to native system libc headers by executing this command:
    clang -E -Wp,-v -xc /dev/null
    Output:
    ==========
    clang: The build tool has reset ENV; --env=std required.
    
    ==========
    Unable to link against libc: Unable to find libc installation: system C compiler exited    with failure code
    

    I'm not sure why this was working before. Perhaps something did change in homebrew after all.

  12. SeekingMeaning commented on Feb 22, 2020

    @SeekingMeaning
    Author

    swi-prolog had a similar issue: Homebrew/homebrew-core#38571

    Fixed in Homebrew/homebrew-core@55ca84b

    Something to do with "shims"

    This is line that prints the error: https://github.com/Homebrew/brew/blob/master/Library/Homebrew/shims/super/cc#L5

    Somewhere along the way environment variables are lost? Zig is calling /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang, so that means at least the PATH variable is not lost

  13. andrewrk commented on Feb 22, 2020

    @andrewrk
    Member

    Somewhere along the way environment variables are lost?

    I think this is correct, and I'm working on a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugos-macos

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions