【问题标题】:cmake suddenly doesn't work with updated Xcodecmake 突然不适用于更新的 Xcode
【发布时间】:2021-12-01 22:40:01
【问题描述】:

我很想解决这个问题。我多年来一直使用 cmake (3.18.2) 和 Xcode,但它突然停止工作。进行以下简单设置:

我制作了一个main.cpp 文件:

#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

还有以下 CMakeLists.txt 文件:

cmake_minimum_required(VERSION 3.14)
project(untitled)

add_executable(untitled main.cpp)

我制作了一个构建文件并在其中运行:

$ cmake ..
-- The C compiler identification is Clang 10.0.0
-- The CXX compiler identification is Clang 10.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /opt/anaconda3/bin/x86_64-apple-darwin13.4.0-clang
-- Check for working C compiler: /opt/anaconda3/bin/x86_64-apple-darwin13.4.0-clang - broken
CMake Error at /opt/anaconda3/share/cmake-3.18/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

    "/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-clang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Users/bmetcalf/Test/build/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/local/bin/gmake cmTC_95f1f/fast && /usr/local/bin/gmake  -f CMakeFiles/cmTC_95f1f.dir/build.make CMakeFiles/cmTC_95f1f.dir/build
    gmake[1]: Entering directory '/Users/bmetcalf/Test/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_95f1f.dir/testCCompiler.c.o
    /opt/anaconda3/bin/x86_64-apple-darwin13.4.0-clang   -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /opt/anaconda3/include  -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -o CMakeFiles/cmTC_95f1f.dir/testCCompiler.c.o -c /Users/bmetcalf/Test/build/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_95f1f
    /opt/anaconda3/bin/cmake -E cmake_link_script CMakeFiles/cmTC_95f1f.dir/link.txt --verbose=1
    /opt/anaconda3/bin/x86_64-apple-darwin13.4.0-clang -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /opt/anaconda3/include  -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath,/opt/anaconda3/lib -L/opt/anaconda3/lib  CMakeFiles/cmTC_95f1f.dir/testCCompiler.c.o -o cmTC_95f1f 
    ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd' for architecture x86_64
    clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
    gmake[1]: *** [CMakeFiles/cmTC_95f1f.dir/build.make:106: cmTC_95f1f] Error 1
    gmake[1]: Leaving directory '/Users/bmetcalf/Test/build/CMakeFiles/CMakeTmp'
    gmake: *** [Makefile:140: cmTC_95f1f/fast] Error 2
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
See also "/Users/bmetcalf/Test/build/CMakeFiles/CMakeOutput.log".
See also "/Users/bmetcalf/Test/build/CMakeFiles/CMakeError.log".

使用的 cmake 来自 anaconda,但自制 cmake 也会发生这种情况。两者都是最新的。

我已经安装了最新的 Xcode 和命令行工具 (v13.0),因为这开始于无法构建 Xcode 项目,但这似乎与 Xcode。我尝试使用xcode-select --resetxcode-select -s /Applications/Xcode.app/Contents/Developer/xcode-select -s /Library/Developer/CommandLineTools 等重置 Xcode 路径。这些都没有帮助。我已经在 Xcode 首选项->位置中设置了命令行工具。

【问题讨论】:

  • 这有帮助吗? stackoverflow.com/questions/63592445/… 作为建议,请始终查看 cmake 输出的内容,因为它非常有用。总是尝试运行它尝试过的命令,看看你得到了什么,然后尝试调整这些命令以解决你的问题
  • 也许这里的解决方案有帮助:stackoverflow.com/questions/63592445/…
  • 我遵循了 stackoverflow.com/questions/63592445/... 中的解决方案,包括重新启动计算机。没有变化。我已经查看了 cmake 输出,但我无法理解它。我不明白为什么 cmake 不能使用本地 clang 而不是 anaconda 版本。测试编译某些测试程序似乎有错误。
  • anaconda 的 cmake 似乎不再兼容 Xcode。它使用来自 cmake 发行版的编译器,这些编译器似乎不适用于测试文件。
  • 正好是condo-cmake-xcode问题link

标签: c++ xcode macos cmake


【解决方案1】:

这是 Anaconda 重置环境变量的结果,以便使用它们自己的构建工具,而不是 Xcode 命令行工具中的构建工具。这些与使用 Anaconda 提供的 cmake 构建 Xcode 项目兼容,但情况不再如此。您甚至无法从其他来源制作 cmake,因为 Anaconda 也会强制它使用 anaconda 的工具。很难以更永久的方式重置所有必要的环境变量或使 Anaconda 与 macOS 10.9 SDK 或更高版本(请参阅link)兼容。也许可以通过某种方式使用 Conda 环境来避免对系统的干扰。对我来说,anaconda 干扰你构建你自己的程序违背了它的目的。

【讨论】:

  • 有一些示例代码可以分享吗?
  • 我不确定你的意思@simon。我回答了我自己的问题,所以原始问题中的代码是我的。
  • 如果此解决方案对您有用,您能否将其标记为已接受,以便在搜索中显示已解决
  • 我不知道该怎么做...
  • 在投票计数下方,您应该会看到一个灰色箭头,作为问题创建者,您可以点击它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-26
  • 1970-01-01
  • 2021-01-12
  • 1970-01-01
  • 2018-07-15
  • 1970-01-01
  • 2016-12-31
相关资源
最近更新 更多