【问题标题】:How do I use CMake on OS X, target the new Arm M1如何在 OS X 上使用 CMake,以新的 Arm M1 为目标
【发布时间】:2020-12-30 17:40:38
【问题描述】:

我有一些使用 cmake 的依赖项需要编译,但我不确定我是否正确执行此操作。我目前在我的 CFLAGS 中为 amd64 使用-march=x86-64,这似乎有效,但我不确定这是否正确,因为当我尝试定位新的 M1 时它不起作用。我还应该做些什么来从命令行使用 cmake 来针对不同的架构?

export CFLAGS="-O2 -march=aarch64 -fomit-frame-pointer -fno-stack-protector -pipe"

cmake -B ${{github.workspace}}/build \
    -G "Unix Makefiles" \
    -D CMAKE_INSTALL_PREFIX=${{github.workspace}}/dist/darwin/arm64 \
    -D CMAKE_VERBOSE_MAKEFILE=ON \
    -D BUILD_SHARED_LIBS=ON \
    -D BUILD_DEMO=ON

cmake --build ${{github.workspace}}/build \
    --parallel 2 \
    --config RelWithDebInfo \
    --clean-first

cmake --install ${{github.workspace}}/build --config RelWithDebInfo

更新:我看到了这个错误。

CMake Error at /usr/local/Cellar/cmake/3.18.4/share/cmake/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

"/Applications/Xcode_12.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"

  is not able to compile a simple test program.

  It fails with the following output:

-- Configuring incomplete, errors occurred!
See also "/Users/runner/work/project/project/build/CMakeFiles/CMakeOutput.log".

error: unknown target CPU 'aarch64'
note: valid target CPU values are: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cooperlake, cannonlake, icelake-client, icelake-server, tigerlake, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, x86-64
make[1]: *** [CMakeFiles/cmTC_72653.dir/testCCompiler.c.o] Error 1
make: *** [cmTC_72653/fast] Error 2

【问题讨论】:

  • 怎么不行,是cmake抛出错误还是别的什么?谢谢。
  • @firmament 用错误更新了帖子,它不是特别有用;只是因为“无法编译简单的测试程序”和“未知的目标 CPU 'aarch64'”而失败。
  • 看起来你可能需要 Xcode 12.2 而这使用的是 12.0
  • 您似乎有一个 x86(-64) 编译器,它只为 x86 相关平台发出代码。要为 arm (aarch64) 发出代码,您需要 ARM (cross-)compiler。
  • @Tsyvarev XCode 大概应该与两者一起提供,因为它是 Apple 的官方工具链。

标签: macos cmake apple-m1


【解决方案1】:

就像添加 CFLAG -target arm64-apple-macos10.5 一样简单。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    • 2017-11-01
    • 2021-12-16
    • 2019-05-10
    • 1970-01-01
    • 2016-08-22
    • 2014-08-14
    相关资源
    最近更新 更多