c++ - M1 MacBook Pro 和 cmake 的编译错误

标签 c++ c xcode macos cmake

我刚拿到我的新 M1 MacBook Pro,正在尝试编译我大学工作所需的代码库。以下是我采取的步骤:

  • 我将终端设置为始终使用 Rosetta 打开。
  • 安装自制软件 using /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • 使用 brew install cmake 安装 cmake
  • 运行 cmake <path to source> (这工作正常)
  • 运行 make (这失败了)

  • 这是我得到的错误:
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stdlib.h:97:15: fatal error: 
          'stdlib.h' file not found
    #include_next <stdlib.h>
    
    我试过卸载并重新安装 Xcode 和 CommandLineTools 无济于事。
    使用 cmake gui 应用程序时,出现不同的错误。我已将其设置为使用 CommandLineTools/SDKs/MacOsX11.0.sdk。
    运行时 make使用此 cmake gui 设置生成和配置构建文件后,出现此错误:
        -- The C compiler identification is AppleClang 12.0.0.12000032
    -- The CXX compiler identification is AppleClang 12.0.0.12000032
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - failed
    -- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
    -- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - broken
    CMake Error at /Applications/CMake.app/Contents/share/cmake-3.18/Modules/CMakeTestCCompiler.cmake:66 (message):
      The C compiler
    
        "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc"
    
      is not able to compile a simple test program.
    
      It fails with the following output:
    
        Change Dir: /Users/freyamurphy/nori/build/ext_build/src/tbb_p-build/CMakeFiles/CMakeTmp
    
    如果我运行命令 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc test.c (简单的 hello world 程序)我收到此错误:
    test.c:1:10: fatal error: 'stdio.h' file not found
    #include "stdio.h"
    
    但是使用 cc test.c一切正常。 (这运行 usr/bin/cc)。
    在我看来,Xcode 可能存在问题。有没有人有任何类似的问题或可以给我一些建议?将不胜感激。

    最佳答案

    安装 xcode 后是否重新打开终端?需要设置环境变量SDKROOT .
    关闭并再次运行终端或在终端中打开一个新选项卡。
    或者在当前终端运行以下命令

    export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
    
    还要确保选择了正确的 xcode 工具链
    # list available xcode toolchains
    xcode-select -p
    
    # select one of listed above
    sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
    

    关于c++ - M1 MacBook Pro 和 cmake 的编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65276102/

    相关文章:

    c++ - Google Test 中的 FRIEND_TEST - 可能的循环依赖?

    C++ - 通过 ref 将对象传递给 CreateThread()

    c - 一个进程是否可以在运行时更改另一个进程中的变量值?

    c - (*Read)(void *p, void *buf, size_t *size); 中返回类型的含义

    c - 如何在 C 中实现 ctime 以存储到字符缓冲区中?

    iphone - ipad/iphone 禁用退出按钮

    ios - UITextView 禁用换行

    C++ new、delete、new[] 和 delete[]

    c++ - casting operator() - 转换为引用并转换为值

    c++ - 设置 -fno-elide-constructors 时,clang Xcode 4.4.1 是否存在错误?