gpt4 book ai didi

c++ - 如何在 CMake 中使用 VC++ 模块

转载 作者:可可西里 更新时间:2023-11-01 18:39:56 27 4
gpt4 key购买 nike

MS Visual C++ 2015 更新 1 implements the Modules proposal .

这是它如何工作的一个例子:
资料来源:

// c.ixx             |  // b.ixx                   |  // a.cpp
module GM; | import GM; | import FM;
export void g() {} | module FM; | int main() { f(); }
| export void f() { g(); } |

构建命令:

set CL=/EHsc /experimental:module   # Default flags for cl.exe
cl.exe /c c.ixx # Produces c.obj, GM.ifc
cl.exe /c b.ixx # Depends on GM.ifc, produces b.obj, FM.ifc
cl.exe /c a.cpp # Depends on FM.ifc, produces a.obj
link.exe a.obj b.obj c.obj # Produces a.exe

依赖图:

c.ixx → GM.ifc → b.ixx → FM.ifc → a.cpp
↘ ↓ ↙
c.obj b.obj a.obj
↘ ↓ ↙
a.exe

每个模块都有一个 file.ixx 及其导出。
该文件将被编译成ModuleName.ifcfile.obj

如果文件导入模块 M,则必须存在 M.ifc 文件。
默认情况下,cl.exe 在当前目录中搜索 .ifc 文件,但可以指定显式名称或搜索路径:

cl.exe /c a.cpp
-- or --
cl.exe /c a.cpp /module:reference FM.ifc
-- or --
cl.exe /c a.cpp /module:search ./

所以,问题是:如何在CMake中使用VC++实现模块
不必使用 MSBuild 后端,Ninja 也可以。

最佳答案

我相信目前还没有人为 C++ 模块完成任何构建系统工作。我们 (Microsoft) 很可能会首先提供 MSBuild 支持,但 CMake 绝对有可能。

关于c++ - 如何在 CMake 中使用 VC++ 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35230327/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com