使用C++模块和import std
使用C++模块和import std
macOS + Clang
Warning
Clang 版本至少为 19
- 安装工具
| |
Note
- AppleClang 版本较老,为了能够用上最新的特性,建议使用 Homebrew 提供的 LLVM。
import std特性需要使用Ninja
- 配置 CMake 命令行
- 生成器:建议使用最新的Multi Config,可以将Debug和Release配置生成在同一个文件夹中
| |
- 系统标准库(macOS专有配置)
| |
Note
- 可使用
xcrun --sdk macosx --show-sdk-path查看具体路径 - 建议使用系统提供的标准库,不建议链接到Homebrew LLVM提供的
libc++libunwind。
std模块的JSON文件
| |
Note
可使用 find /opt/homebrew -name "libc++.modules.json" -maxdepth 10 寻找具体路径,然后重写为 /opt/homebrew/opt/llvm/...
- 配置
CMakeLists.txt
CMakeLists.txt
| |
Linux + gcc
Warning
gcc 版本至少为15
Note
未提及的操作和macOS完全相同
- 安装工具
| |
| |
std模块的JSON文件:使用下面的命令获取
| |
- 修改CMakeLists.txt
| |
Windows + MSVC
Warning
MSVC 版本至少为 14.36(等同于 Visual Studio 2022 v17.6)
具体操作基本同macOS,但是不需要提供 CMAKE_CXX_STDLIB_MODULES_JSON
最后更新于