<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/github---cpp2rust-cpp2rust-cpp2rust-automatic-translation-of-c-to-safe-rust-cf9bjbbr6" -->

---
title: GitHub - Cpp2Rust/cpp2rust: Cpp2Rust: Automatic...
description: Cpp2Rust is an open source tool that automatically translates C++ code to fully safe Rust using a syntax-driven approach based on Clang's AST. It parses C++...
canonical: https://daily.dev/posts/github---cpp2rust-cpp2rust-cpp2rust-automatic-translation-of-c-to-safe-rust-cf9bjbbr6
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: GitHub - Cpp2Rust/cpp2rust: Cpp2Rust: Automatic Translation of C++ to Safe Rust | daily.dev
og:description: Cpp2Rust is an open source tool that automatically translates C++ code to fully safe Rust using a syntax-driven approach based on Clang's AST. It parses C++...
og:url: https://daily.dev/posts/github---cpp2rust-cpp2rust-cpp2rust-automatic-translation-of-c-to-safe-rust-cf9bjbbr6
og:image: https://api.daily.dev/og/posts/CF9BJbbr6.png
og:image:alt: GitHub - Cpp2Rust/cpp2rust: Cpp2Rust: Automatic Translation of C++ to Safe Rust
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# GitHub - Cpp2Rust/cpp2rust: Cpp2Rust: Automatic Translation of C++ to Safe Rust

**[Lobsters](https://daily.dev/sources/lobsters)** · 2 min read · 14 upvotes · 0 comments

## Summary

Cpp2Rust is an open source tool that automatically translates C++ code to fully safe Rust using a syntax-driven approach based on Clang's AST. It parses C++ files, traverses the AST, and emits Rust code, relying on a runtime library called libcc2rs that models C pointer semantics (null, arithmetic, aliasing) through a Ptr<T> type that satisfies Rust's borrow checker. By default it uses a reference counting model to produce safe Rust, with an optional unsafe mode for debugging and performance comparisons. The project is backed by a research paper published at PLDI 2026.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://github.com/Cpp2Rust/cpp2rust>

## Questions this post answers

### Is there a tool that automatically translates C++ code into safe Rust?

Cpp2Rust is a syntax-driven translator that converts C++ into safe Rust automatically, based on clang's AST. It parses C++ files into an AST, emits Rust code, and links against a runtime library called libcc2rs that models C pointer semantics (null, arithmetic, aliasing) through a Ptr<T> type while satisfying Rust's borrow checker via runtime checks. By default it emits fully safe Rust using a reference-counting model.

_Teams weighing a C++ to Rust migration can follow tool developments like this one on daily.dev._

### How do I generate unsafe Rust instead of safe Rust when translating a C++ codebase with cpp2rust?

Pass the --model=unsafe flag on the command line, for example: ./build/cpp2rust/cpp2rust --file=<file>.cpp -o=<file>.rs --model=unsafe. This generates unsafe Rust rather than the default reference-counting safe output, intended for debugging and performance comparisons against the safe translation.

_Developers comparing safe versus unsafe Rust output can track tooling like this on daily.dev._

### How do I translate an entire C++ project rather than a single file with cpp2rust?

Generate a compile_commands.json for the project first (with CMake, add -DCMAKE_EXPORT_COMPILE_COMMANDS=ON), then run cpp2rust with the --dir=<dir> flag pointing to the directory containing that file, along with -o <output>.rs to specify the output Rust file.

_Engineers planning whole-project C++ to Rust conversions can follow this workflow via daily.dev._

## Similar posts on daily.dev

- [Automatically Translating C to Rust – Communications of the ACM](https://daily.dev/posts/automatically-translating-c-to-rust-communications-of-the-acm-o6bpcy6bu) · Hacker News · 5 upvotes · 1 comments
- [Rewriting the world in Rust — Bitfield Consulting](https://daily.dev/posts/rewriting-the-world-in-rust-bitfield-consulting-vxpqrwzmv) · Bitfield Consulting · 69 upvotes · 8 comments
- [C\+\+ to Rust Migration: By Luca Palmieri from Mainmatter](https://daily.dev/posts/c-to-rust-migration-by-luca-palmieri-from-mainmatter-rmmgwzjbp) · JetBrains · 4 upvotes · 0 comments
- [AI Code Transforms C to Rust for Safer Software](https://daily.dev/posts/ai-code-transforms-c-to-rust-for-safer-software-xgjsw1cts) · IEEE Spectrum · 40 upvotes · 11 comments

---

Tags: [#rust](https://daily.dev/tags/rust), [#c++](https://daily.dev/tags/c++)

[View this post on daily.dev](https://daily.dev/posts/github---cpp2rust-cpp2rust-cpp2rust-automatic-translation-of-c-to-safe-rust-cf9bjbbr6)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"GitHub - Cpp2Rust/cpp2rust: Cpp2Rust: Automatic Translation of C++ to Safe Rust","url":"https://daily.dev/posts/github---cpp2rust-cpp2rust-cpp2rust-automatic-translation-of-c-to-safe-rust-cf9bjbbr6","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/github---cpp2rust-cpp2rust-cpp2rust-automatic-translation-of-c-to-safe-rust-cf9bjbbr6"},"datePublished":"2026-07-10T15:13:56.723Z","dateModified":"2026-09-13T21:40:53.960Z","description":"Cpp2Rust is an open source tool that automatically translates C++ code to fully safe Rust using a syntax-driven approach based on Clang's AST. It parses C++...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/cbf35c0dcebb2743c23f22c05e41865f?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/cbf35c0dcebb2743c23f22c05e41865f?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Lobsters","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Lobsters","logo":"https://media.daily.dev/image/upload/s--tl8v_Fku--/f_auto,t_logo/v1698841318/logos/lobste.jpg","url":"https://daily.dev/sources/lobsters"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/github---cpp2rust-cpp2rust-cpp2rust-automatic-translation-of-c-to-safe-rust-cf9bjbbr6","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":14},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"rust,c++","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Lobsters","item":"https://daily.dev/sources/lobsters"},{"@type":"ListItem","position":3,"name":"GitHub - Cpp2Rust/cpp2rust: Cpp2Rust: Automatic Translation of C++ to Safe Rust"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/github---cpp2rust-cpp2rust-cpp2rust-automatic-translation-of-c-to-safe-rust-cf9bjbbr6#faq","mainEntity":[{"@type":"Question","name":"Is there a tool that automatically translates C++ code into safe Rust?","acceptedAnswer":{"@type":"Answer","text":"Cpp2Rust is a syntax-driven translator that converts C++ into safe Rust automatically, based on clang's AST. It parses C++ files into an AST, emits Rust code, and links against a runtime library called libcc2rs that models C pointer semantics (null, arithmetic, aliasing) through a Ptr<T> type while satisfying Rust's borrow checker via runtime checks. By default it emits fully safe Rust using a reference-counting model. Teams weighing a C++ to Rust migration can follow tool developments like this one on daily.dev."}},{"@type":"Question","name":"How do I generate unsafe Rust instead of safe Rust when translating a C++ codebase with cpp2rust?","acceptedAnswer":{"@type":"Answer","text":"Pass the --model=unsafe flag on the command line, for example: ./build/cpp2rust/cpp2rust --file=<file>.cpp -o=<file>.rs --model=unsafe. This generates unsafe Rust rather than the default reference-counting safe output, intended for debugging and performance comparisons against the safe translation. Developers comparing safe versus unsafe Rust output can track tooling like this on daily.dev."}},{"@type":"Question","name":"How do I translate an entire C++ project rather than a single file with cpp2rust?","acceptedAnswer":{"@type":"Answer","text":"Generate a compile_commands.json for the project first (with CMake, add -DCMAKE_EXPORT_COMPILE_COMMANDS=ON), then run cpp2rust with the --dir=<dir> flag pointing to the directory containing that file, along with -o <output>.rs to specify the output Rust file. Engineers planning whole-project C++ to Rust conversions can follow this workflow via daily.dev."}}]}
```

