TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #25840 4
cxvm: pin a GCC or Clang version per project on Linux (pyenv/nvm, but for C++ compilers)

I do embedded Linux work, and every few months a project needs a host GCC that my distro doesn't ship: usually one with the same major version as an old cross toolchain from a BSP. Building one by hand is tedious. Switching `gcc` with update-alternatives changes it for every project on the machine, which is worse.

So I wrote cxvm. It keeps as many GCC and Clang versions as you want under your home directory, and each project pins one:

```sh
cxvm install gcc@13 # GCC 13.4.0, into ~/.local/share/cxvm
cd my-project
cxvm use gcc@13 # pins gcc@13.4.0 in .cxvmrc, generates .cxvm/
cmake -S . -B build/gcc-13.4.0 -DCMAKE_TOOLCHAIN_FILE=.cxvm/toolchain.cmake
```

You commit `.cxvmrc`. Whoever clones the repo runs `cxvm install` and gets the same compiler.

Things I cared about:

- Nothing wraps the compiler. The generated toolchain file names real paths in the store, so the build still works if cxvm is off PATH or uninstalled.
- A program built with a GCC newer than the host's gets an rpath to that GCC's libstdc++. cxvm never sets LD_LIBRARY_PATH.
- Clang can use the libstdc++ of a GCC you choose: `cxvm use clang@19 --gcc gcc@13`.
- Every download is checked against a sha256 built into the binary, and a toolchain only enters the store after a smoke test. No root.

Clang comes from LLVM's official releases (11 to 18, plus every release since 19.1.0). GCC comes from xPack builds (8.5.0 and 11.2.0 to 15.2.0), or cxvm builds it from the GNU tarball. I've built 10.5.0 and 16.2.0 that way; releases back to 4.8.5 are in the catalogue but untested.

Limits: x86_64 Linux only, native compilers only, and the list of releases is compiled into cxvm, so a new GCC needs a new cxvm release. `cxvm link /opt/gcc-11` registers a compiler you already have.

It's a single static binary written in Rust. I built it with a lot of help from Claude Code; I made the design calls and tested it on real hosts myself.

Repo: https://github.com/AndreaRicchi/cxvm

It's 0.1.0, and I've only run it on Ubuntu 24.04 and 26.04. If it breaks on Fedora, Arch or anything else, I'd like to know, and also which versions or workflows you'd need next.

https://redd.it/1x42iuf
@r_cpp
GitHub GitHub - AndreaRicchi/cxvm: Per-project C/C++ compiler versions for x86_64 Linux Per-project C/C++ compiler versions for x86_64 Linux - AndreaRicchi/cxvm
More from @r_cpp
  1. Oct 12, 2026New C++ Conference Videos Released This Month - October 2026 (Updated To Include Videos Re…
  2. Oct 12, 2026cppreference-doc for Qt Creator Release cppreference C++ v2025.12.01 · cristianadam/cppref…
  3. Oct 12, 2026ACCU Overload Journal 195 - October 2026 https://accu.org/journals/overload/overload195 ht…
  4. Oct 12, 2026C++ Contracts C++ contracts are a good thing, why are people saying it's a bad thing? Anyb…
  5. Oct 11, 2026wxWidgets 3.2.12 and 3.3.4 Released https://wxwidgets.org/news/2026/10/wxwidgets-3.2.12-an…
  6. Oct 11, 2026VKRT NES Remaster — an open-source C++20 NES emulator with an observation-driven remasteri…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →