【发布时间】:2022-01-07 02:22:11
【问题描述】:
根据official documentation,Clang 13 通过使用-fmodules 命令行参数来支持 C++20 模块。
我什至无法在基于 Intel 或 M1 的 mac 上使用 Clang 13 (macOS Monterey) 编译基本模块。
假设文件module.cpp的文本内容如下:
export module a;
export int f(int a, int b) {
return a + b;
}
运行以下:
$ clang++ --version
Apple clang version 13.0.0 (clang-1300.0.29.3)
Target: x86_64-apple-darwin21.1.0
$ clang++ -std=c++20 -stdlib=libc++ -fmodules -fbuiltin-module-map -c module.cpp
module.cpp:1:8: error: expected template
export module a;
^
module.cpp:1:8: error: unknown type name 'module'
module.cpp:3:8: error: expected template
export int f(int a, int b) {
^
3 errors generated.
在 ARM M1 芯片上测试结果相同:
$ clang++ --version
Apple clang version 13.0.0 (clang-1300.0.29.3)
Target: arm64-apple-darwin21.1.0
是否有其他方法可以让模块正常工作,或者 Apple Clang 13 是否存在一些未记录的 C++20 模块限制?
注意:使用实验性 -fmodules-ts 标志进行编译是可行的。
【问题讨论】:
-
homebrew 的 clang 13 与
-fmodules配合使用,在 m1 mac 上测试。 -
注意:不幸的是,apple clang 和 mainline clang 是不同的东西。
-
@Mgetz 感谢您的确认 - 我确实在运行 Xcode 版本 - HomeBrew Clang 似乎与官方文档相符
-
@VainMan - 感谢您抽出宝贵时间 - 这是 Xcode 与 Homebrew Clang 的问题
标签: c++20 clang++ apple-m1 c++-modules macos-monterey