<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57289>57289</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[C++20] [Modules] Enable to compile demo examples in one go
</td>
</tr>
<tr>
<th>Labels</th>
<td>
c++20,
clang:driver,
clang:modules
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ChuanqiXu9
</td>
</tr>
</table>
<pre>
See https://discourse.llvm.org/t/make-command-line-support-for-c-20-module-uniform-with-gcc/59144 for a completed example.
Simply, for a hello world example:
```C++
// say_hello.cpp
module;
#include <iostream>
#include <string_view>
export module Hello;
export void SayHello(std::string_view const &name)
{
std::cout << "Hello " << name << "!\n";
}
// main.cpp
#include <string_view>
import Hello;
int main() {
SayHello("world");
return 0;
}
```
The GCC could compile it in one go:
```
g++ -std=c++20 -fmodules-ts say_hello.cpp main.cpp
```
But clang need to compile it in two steps at least:
```
clang++ -std=c++20 --precompile say_hello.cpp -o Hello.pcm
clang++ -std=c++20 -fprebuilt-module-path=. main.cpp Hello.pcm
```
So in this demo example, the command line interface of GCC is slightly more friendly than Clang.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVE1zozgQ_TXi0gUFwl8cOCR4dvcyp-xhbykZGtCMkFhJJPG_nxbYxM5kZrdKNpJaar3Xr7tPpjmXT4jQez86lj8w_geNRrraTNZhotTLkBjb0aan3yC-Y1ybYRC6iZXUGLtpHI31cWtsXMc8jQfTTArjSUvaGuJX6fu4q2u6vC2yzQZoFwSQj1GhxwbwTYRpwtIjSx-W_ydJW2fGq8vpHpUy8GqsWs8HrDc32C5dRsX4YxjL7swGnDg_zy6SehwXy4KS5evBXOpaTQ0CyytpnLcoBpZ_-cxMRqm75xeJr-sJfAtRgMUt_BUeW51fbC9GNvAkzouRH5xvAon84cYfxUU7D4zvtBiQ8eLy_v7iCmC9RQL5gIYGneez1zC57gUHN3bGM7atdJitpPfHuzANQur3CP03ZxIp8LonK7WfHRFBgg83yG-oE4pZzBlXsd4FsOgnqyH9BONV4FvV_-4R_qwqitpEmRFySlL0pQepwWiEzvwqTZZltyQLxHNUj_Wy5CnE7aKki727T5-PUfoM1iMpUyuhO9BIGe7NB2j-1ZCOODoQHhQK538Pc_b1K6gQx6PF6wP3WGOzqJOM9fC_XLXk6jRJ5a9lPArf05lkpf3R4acBeDIzzV46aHAwa81SQXuS7NJAIDQQOujRtqJGMO0sJl1ySna9V2eqJ4vQWom6oZXvhYYqMEgiLLPdLuM8S3kRNWXeFHkhIi-9wpJtH6srKbY9Aq2_LnKG1RctThSpG1VuMbr33Ikmq8r7xthRN5tOCV2kReiNlw9JYL5hHVqkdG6ih6jd7fmhiPqS73mNAnl2OGT702bTinZDk3y_43vE-hApcULlAmqqh1WNuTbm0l00yx8aK1_Q_rx_SdVg2B4jWfKU8_TA85Rn-7RIsNjWRZqm2RazbNvu2CZFUlOtvT2y5czhNHWOjEo6796NwjnZUR7P-Mi_mHxvbFn1k9D_yn-mIpoZlzPdH-co4wQ">