本文介绍了如何在clang ++中使用模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

模块是可能添加到C ++ 1z的#includes的替代品。 。

使用

import std.io;

无法正常工作(编译),因为C ++ 1z规范模块(包括语法)不是最终的。

in a C++ source file does not work (compile) yet, as the C++1z specification for modules (which includes syntax) isn't final.

指出,当传递 -fmodules 标志时,#includes将被重写到他们适当的进口。然而,检查预处理器建议另外(test.cpp只包含 #include< stdio.h> 和一个空的main):

The clang documentation states that, when passing the -fmodules flag, #includes will be rewritten to their appropriate imports. However, checking the preprocessor suggests otherwise (test.cpp only contains #include <stdio.h> and an empty main):

$ clang++-3.5 -fmodules -E test.cpp -o test
$ grep " printf " test
extern int printf (const char *__restrict __format, ...);


$ b > vs没有标志产生相同的目标文件。

Furthermore, compiling this test file with -fmodules vs no flags at all produces the same object file.

我做错了什么?

推荐答案

像你提到的,clang还没有一个C ++语法的导入,
所以我怀疑 #include 指令将在预处理文件时被重写为导入,因此这可能不是测试模块是否按预期工作的最佳方式。

Like you mentioned, clang does not yet have a C++ syntax for imports,so I doubt that #include directives are going to be literally rewritten as imports when preprocessing a file, so that may not be the best way to test if modules are working as intended.

但是,如果你显式地设置 -fmodules-cache-path =< path> ,你可以在构建过程中观察到用预编译的模块文件有任何模块涉及。

However, if you set -fmodules-cache-path=<path> explicitly, you can observe clang populating it with precompiled module files (*.pcm) during a build - if there are any modules involved.

您需要使用libc ++(似乎是一个module.modulemap从3.7.0版本)如果你想使用模块启用标准库现在 - 虽然在我的经验,这不是完全正在工作。
(Visual Studio 2015的C ++编译器也应该获得某种形式的模块支持与11月的更新1)

You'll need to use libc++ (which seems to come with a module.modulemap as of version 3.7.0) if you want to use a modules enabled standard library right now - though in my experience this isn't working entirely just yet.(Visual Studio 2015's C++ compiler is also supposed to get some form of module support with Update 1 in November)

独立于stdlib,你仍然可以使用模块在你自己的代码。 clang文档包含的详细说明,但
我还设置了一个示例项目(使用cmake),应该生成一个高速缓存目录,包含一些模块。

Independently of the stdlib, you could still use modules in your own code. The clang docs contain a detailed description of the Module Map Language, butI've also set up a little example project here (using cmake) that should generate a cache directory with some modules when built.

这篇关于如何在clang ++中使用模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:41