LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

clang-repl

Interactive C++ interpreter from the LLVM Clang project

TLDR

Start the REPL
$ clang-repl
copy
Load a source file by including it
$ clang-repl '#include "[test.cpp]"'
copy
Run statements passed as arguments
$ clang-repl '#include <iostream>' 'std::cout << "test\n";'
copy
At the prompt, print a value
$ 24
copy
Undo the last statement
$ %undo
copy
Link a shared library
$ %lib [library.so.1]
copy
Leave the session
$ %quit
copy
Show meta-command help
$ %help
copy

SYNOPSIS

clang-repl [statements]...

DESCRIPTION

clang-repl is LLVM's interactive C++ interpreter. It reads statements, compiles them with Clang, and prints results. A statement can be given on the command line or typed at the prompt. To bring in a file, pass a quoted include of that path.Lines that start with % are meta-commands, not C++. %undo drops the last statement, %lib loads a dynamic library, %help lists the meta-commands, and %quit exits. Ctrl-C also leaves the session.This is its own program. It is not a subcommand of clang, though it ships with the same LLVM/Clang toolchain.

INSTALL

sudo apk add clang22-extra-tools
copy

CAVEATS

Code typed at the prompt runs with the privileges of the process, and it can load libraries from disk. Treat the session like a compiler, not a sandbox.

SEE ALSO

clang(1), clang++(1), clangd(1)

RESOURCES

Copied to clipboard
Kai