使用clang将std lib导入为模块 [英] Import std lib as modules with clang
问题描述
我正在用clang进行模块的实验,并且希望将标准库作为模块而不是包含在模块中.
I am experimenting with modules in clang, and would like to include the standard lib as modules instead of as includes.
目前我正在这样做
#include <iostream>
#include <string>
似乎您在msvc中应该能够导入标准库,例如
It seems that you in msvc should be able to import standard libs with for example
import std.core;
但是在使用clang时,这似乎没有实现或以其他方式实现.
When using clang however this does not seem to be implemented, or implemented in another way.
我的问题是:是否可以像微软的建议那样导入stl-includes,或者是否可以将标准的lib include映射到somhow模块.
My question is: Is it possible to import stl-includes like microsoft suggest, or is it possible to map standard lib includes to modules somhow.
注意:之所以不能使用 #include< ...>
或 #import< ...>
,是因为可能存在其他错误提出自己的问题.因此,我认为,如果可能的话,现在要获取 import std.core
或类似的方法.
Note: The reason I cannot use #include <...>
or #import <...>
is because of other errors that might get its own question. So I think that getting import std.core
or similar is the way to go now if it is possible.
ModernesCpp 也提到了std.core.>
ModernesCpp also mentions std.core.
推荐答案
C ++ 20标准不包括C ++标准库的模块定义.Visual Studio确实做到了(不幸的是),并且许多不良站点的行为都像是标准行为.但事实并非如此;这只是微软的事情.
The C++20 standard does not include module definitions for the C++ standard library. Visual Studio does (unfortunately), and a lot of bad sites out there will act like this is standard. But it's not; it's just a Microsoft thing.
如果要通过跨平台的模块包含C ++标准库,则必须使用 import< header-name>
语法或编写自己的导入标头的标准库模块并导出特定的C ++声明.
If you want to include the C++ standard library through a module across platforms, you will have to either use import <header-name>
syntax or write your own standard library modules that import the headers and export specific C++ declarations.
这篇关于使用clang将std lib导入为模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!