C++ Game Utility Libraries: for Game Dev Rustaceans
Tags: cpp, gamedev
Published: 2024-03-13 18:06:18

---
title: "C++ Game Utility Libraries: for Game Dev Rustaceans"
published: "true"
description: "C++ Game Utility Libraries: dependencies for C++ game dev, with Rust 🦀 equivalents for clap, dbg! & more, for Rustaceans working in C++."
tags: "cplusplus, gamedev"
canonical_url: "https://rodneylab.com/c++-game-utility-libraries/"
cover_image: "https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3wa4eyyzmhjpejwjndab.png"
---

## 🖥️ C++ Game Development Utility Libraries

Coming from a Rust background, you might be looking for some C++ game development utility libraries.  We are talking about the C++ equivalents for clap, `dbg!`, `format!` and log here.  With the C++ ecosystem working a little differently to Rust&rsquo;s it can be harder for a newcomer to discover libraries offering common utility functions for your game.

Although we mentioned Rust developers, hopefully the post is also useful to anyone new to C++, with other backgrounds, or coming back to C++ after some time away.

Let me know if you find the post useful, and of course, if you would like to see similar content covering other C++ tooling.  If you are looking for game engine and ECS options, see the  <a href="https://rodneylab.com/c++-game-dev-libraries/">recent post on C++ Game Dev</a>.

## ⌨️ C++ Utility Libraries with Rust Equivalents

### CLI11

** Command line parser for C11++ and later / Rust equivalent: clap crate**


CLI11 offers CLI argument parsing in modern C++.  This library needs minimal boilerplate code and supports some nice-to-have features, such as input validation and **automatic usage and help message** generation.  It also works well with CMake.  Definitely worth adding to your C++ Game Dev tool belt, as even for GUI games, you might want to accept CLI parameters for adjusting screen size, for example.

There&rsquo;s much more to say; it just works!

**Learn more about CLI11 here**:
- GitHub repo: <a href="https://github.com/CLIUtils/CLI11">CLIUtils/CLI11</a>
- Book: <a aria-label="CL I 11 book" href="https://cliutils.github.io/CLI11/book/">CLI11 book</a>
- Code Examples: <a aria-label="C L I 11 Examples" href="https://github.com/CLIUtils/CLI11#examples">CLI11 Examples</a>

### dbg(&hellip;)

**C++ macro for debugging / Rust equivalent: inbuilt macro: `dbg!(x)`**

The <a href="https://doc.rust-lang.org/std/macro.dbg.html">Rust dbg macro</a> offers a quick way to add a printout of a variable in your app to the console.  This package, was inspired by the Rust macro, and brings you similar features.  Of course, you could use `std::cout`, `std::format` or `fmt::format` (see fmtlib, below).  Those are better suited to more general use cases, and `dbg(…)` adds the source file and line number in the output, making it ideal for quick debugging.  The other advantage of using this library, is that it becomes easier to remove your debug output for release builds, or when you no longer need it in the code.

Example from the GitHub repo:

```cpp
  std::vector<int32_t> numbers{b, 13, 42};
  dbg(numbers);  // TERMINAL OUTPUT: [example.cpp:21 (main)] numbers = {7, 13, 42} (std::vector<int32_t>)
```

The library works well with CMake.

**Learn more about dbg(&hellip;) here**:
- GitHub repo: <a href="https://github.com/sharkdp/dbg-macro">sharkdp/dbg-macro</a>

### fmtlib
**Rust equivalent: inbuilt macro: `format!("Some text {x}")`**

<a href="https://en.cppreference.com/w/cpp/utility/format/format">C++20 brings `std::format`</a>, improving C++ developer experience for formatting strings.  If you have to use older standards, though, add `fmtlib` to your repo.  It plays well with CMake and you can <a aria-label="use C P M to add f m t lib to your project" href="https://github.com/cpm-cmake/CPM.cmake/tree/master/examples/fmt">use CPM to add fmtlib to your project</a>.  The library supports many Rust `format` macro features, and makes code far cleaner when you need to do string interpolation with variables.

Example from the GitHub repo:

```cpp
std::string s = fmt::format("The answer is {}.", 42);
```

**Learn more about fmtlib here**:
- GitHub repo: <a href="https://github.com/fmtlib/fmt">fmtlib/fmt</a>
- Documentation: <a aria-label="f m t lib docs" href="https://fmt.dev//">fmtlib docs</a>
- Cheat Sheets: <a aria-label="f m t lib Cheat Sheets" href="https://hackingcpp.com/cpp/libs/fmt.html">fmtlib Cheat Sheets</a>

### FTXUI
**C++ library for terminal-based user interfaces / Rust equivalent: ratatui crate**

Functional Terminal (X) User Interface (**FTXUI**) is a neat library for creating text user interfaces.  You could design your a game using it; in fact, there is a list of existing FTXUI games in the GitHub repo, including a Minesweeper clone.  FTXUI generates cross-platform executables and also supports generating WebAssembly (**WASM**) output, for sharing the app on the Web.

See CMake FetchContent details on the GitHub repo. 

**Learn more about FTXUI here**:
- GitHub repo: <a href="https://github.com/ArthurSonzogni/FTXUI">ArthurSonzogni/FTXUI</a>
- Documentation: <a aria-label="F T X U I docs" href="https://arthursonzogni.github.io/FTXUI/">FTXUI docs</a>
- WebAssembly Code Examples: <a aria-label="F T X U I Examples" href="https://arthursonzogni.github.io/FTXUI/examples/">FTXUI Examples</a>

### spdlog

**Fast C++ logging library / Rust equivalent: log crate**

spdlog provides logging, generating messages with the usual log levels (trace, debug, info etc.).  You can format messages using the fmtlib syntax (see fmtlib, above).  Its speed makes it is a nice choice to add to your toolkit for <a href="https://www.honeycomb.io/blog/what-is-observability-key-components-best-practices">building observability into your C++ game</a>, right inside the game loop.

Alternatives are <a aria-label="g log from Google"  href="https://github.com/google/glog">glog from Google</a> is full-featured, like spdlog, while <a aria-label="P log offers a lightweight alternative" href="https://github.com/SergiusTheBest/plog">Plog offers a lightweight alternative</a>.  Both are worthy upgrades on using C++ built-in `std::clog`.

**Learn more about spdlog here**:
- GitHub repo: <a href="https://github.com/gabime/spdlog">gabime/spdlog</a>
- Documentation: <a href="https://github.com/gabime/spdlog/wiki/1.-QuickStart">spdlog wiki</a>

## 🙌🏽 C++ Game Utility Libraries: Wrapping Up

In this C++ game utility libraries, we had a look at some C++ libraries useful for game dev.  More specifically, we saw:

- **C++ equivalents to poplar Rust libraries**;
- considered **spdlog for observability** in your C++ game; and
- **FTXUI for text-based games**.

I hope you found this useful.  Do let me know if you would like to see more similar content.  Also reach out if there is anything I could improve to provide a better experience for you.

## 🙏🏽 C++ Game Utility Libraries: Feedback

If you have found this post useful, see links below for further related content on this site.  Let me know if there are any ways I can improve on it. I hope you will use the code or starter in your own projects. Be sure to share your work on X, giving me a mention, so I can see what you did. Finally, be sure to let me know ideas for other short videos you would like to see. Read on to find ways to get in touch, further below. If you have found this post useful, even though you can only afford even a tiny contribution, please <a aria-label="Support Rodney Lab via Buy me a Coffee" href="https://rodneylab.com/giving/">consider supporting me through Buy me a Coffee</a>.

Finally, feel free to share the post on your social media accounts for all your followers who will find it useful. As well as leaving a comment below, you can get in touch via <a href="https://twitter.com/messages/compose?recipient_id=1323579817258831875">@askRodney</a> on X (previously Twitter) and also, join the <a href="https://matrix.to/#/%23rodney:matrix.org">#rodney</a> Element Matrix room. Also, see <a aria-label="Get in touch with Rodney Lab" href="https://rodneylab.com/contact/">further ways to get in touch with Rodney Lab</a>. I post regularly on <a href="https://rodneylab.com/tags/gaming/">Game Dev</a> as well as <a href="https://rodneylab.com/tags/rust/">Rust</a> and <a href="https://rodneylab.com/tags/c++/">C++</a> (among other topics). Also, <a aria-label="Subscribe to the   Rodney Lab newsletter" href="https://newsletter.rodneylab.com/issue/latest-issue">subscribe to the newsletter to keep up-to-date</a> with our latest projects.