File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -1213,6 +1213,45 @@ instead a real binary. There are 4 potential solutions to the problem:
1213
1213
$ clang-scan-deps -format=p1689 -- <path-to-compiler-executable>/clang++ -std=c++20 -resource-dir <resource-dir> mod.cppm -c -o mod.o
1214
1214
1215
1215
1216
+ Import modules with clang-repl
1217
+ ==============================
1218
+
1219
+ We're able to import C++20 named modules with clang-repl.
1220
+
1221
+ Let's start with a simple example:
1222
+
1223
+ .. code-block :: c++
1224
+
1225
+ // M.cppm
1226
+ export module M;
1227
+ export const char* Hello() {
1228
+ return "Hello Interpreter for Modules!";
1229
+ }
1230
+
1231
+ We still need to compile the named module in ahead.
1232
+
1233
+ .. code-block :: console
1234
+
1235
+ $ clang++ -std=c++20 M.cppm --precompile -o M.pcm
1236
+ $ clang++ M.pcm -c -o M.o
1237
+ $ clang++ -shared M.o -o libM.so
1238
+
1239
+ Note that we need to compile the module unit into a dynamic library so that the clang-repl
1240
+ can load the object files of the module units.
1241
+
1242
+ Then we are able to import module ``M `` in clang-repl.
1243
+
1244
+ .. code-block :: console
1245
+
1246
+ $ clang-repl -Xcc=-std=c++20 -Xcc=-fprebuilt-module-path=.
1247
+ # We need to load the dynamic library first before importing the modules.
1248
+ clang-repl> %lib libM.so
1249
+ clang-repl> import M;
1250
+ clang-repl> extern "C" int printf(const char *, ...);
1251
+ clang-repl> printf("%s\n", Hello());
1252
+ Hello Interpreter for Modules!
1253
+ clang-repl> %quit
1254
+
1216
1255
Possible Questions
1217
1256
==================
1218
1257
You can’t perform that action at this time.
0 commit comments