[英]C++20 modules on clang (Windows): typeinfo error in simplest example
文件first_module.cppm
export module first_module;
int foo(int x) {
return x;
}
export int e = 42;
export int bar() {
return foo(e);
}
預編譯(沒問題):
$ clang++ --std=c++20 -fmodules --precompile first_module.cppm -o first_module.pcm
編譯器信息:
$ clang++ -v
clang version 10.0.0
Target: x86_64-pc-windows-msvc
文件first-main.cc
import first_module;
int main() {
return bar();
}
編譯(沒問題):
$ clang++ --std=c++20 -fmodules first-main.cc -fmodule-file=first_module.pcm first_module.pcm
一切都好。
文件second-main.cc
import first_module;
#include <iostream>
int main() {
std::cout << bar() << std::endl;
}
編譯方式相同:
$ clang++ --std=c++20 -fmodules second-main.cc -fmodule-file=first_module.pcm first_module.pcm
結果:大量錯誤,例如:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\eh.h:56:14: error: reference to 'type_info' is ambiguous
_In_ type_info const& _Type,
^
note: candidate found by name lookup is 'type_info'
note: candidate found by name lookup is 'type_info'
我覺得我做錯了什么,因為我有最新的 MSVS(最近更新),最新的 clang,但在 Windows 上的一些瑣碎示例仍然無法正常工作。
或者這可能是已知的錯誤? 試着google了一下,沒有結果。
核心問題在於您當前的Clang
安裝它正在使用MSVC
工具鏈,並且當您使用帶有 Microsoft 工具鏈的#include
指令和Clang
使用modules
功能進行編譯時,存在一個已知問題。
你可以在這里找到它,自 2018 年以來打開https://github.com/llvm/llvm-project/issues/38400
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.