BGCS.Cpp2C 2.0.4

dotnet add package BGCS.Cpp2C --version 2.0.4
                    
NuGet\Install-Package BGCS.Cpp2C -Version 2.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BGCS.Cpp2C" Version="2.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BGCS.Cpp2C" Version="2.0.4" />
                    
Directory.Packages.props
<PackageReference Include="BGCS.Cpp2C" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BGCS.Cpp2C --version 2.0.4
                    
#r "nuget: BGCS.Cpp2C, 2.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BGCS.Cpp2C@2.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BGCS.Cpp2C&version=2.0.4
                    
Install as a Cake Addin
#tool nuget:?package=BGCS.Cpp2C&version=2.0.4
                    
Install as a Cake Tool

BGCS.Cpp2C

BGCS.Cpp2C generates an extern "C" ABI bridge for C++ classes, functions, explicit template instances, ownership types, and supported standard-library semantics. The resulting C surface can be consumed by P/Invoke and can optionally be passed directly to BGCS to generate matching C# bindings.

Common C/C++ is automatic. Complex semantics use the final extension architecture: declarative type/callable lowerings, typed lowering plugins, or explicit project-owned C shims. Unsupported or ambiguous constructs are diagnosed instead of being silently treated as blittable values; projects may explicitly accept reviewed or unsafe lowerings through LoweringSafetyPolicy.

Install

dotnet add package BGCS.Cpp2C

Command-line users can install the BindGen-CS .NET tool and run bindgen-cs bridge bridge.json; the tool already includes this package.

Generate from configuration

{
  "ConfigVersion": 1,
  "EntryFiles": ["include/library.hpp"],
  "AllowedHeaders": ["include/library.hpp"],
  "OutputPath": "GeneratedBridge",
  "LanguageStandard": "c++23",
  "GenerateBuildManifest": true,
  "GenerateCSharpBindings": true,
  "CSharpNamespace": "Example.Native",
  "CSharpApiName": "NativeApi",
  "NativeLibraryName": "example",
  "CSharpOutputPath": "GeneratedBindings",
  "CSharpStrictSafetySeverity": "SuppressFriendly",
  "LoweringSafetyPolicy": "VerifiedOnly",
  "TypeLowerings": [],
  "CallableLowerings": [],
  "NativeShims": [],
  "PluginAssemblies": []
}
using BGCS.Cpp2C;

Cpp2CGeneratorConfig config = Cpp2CGeneratorConfig.Load("bridge.json");
Cpp2CCodeGenerator generator = new(config);
generator.GenerateConfigured();

if (generator.LastResult is { Success: false } result)
{
    foreach (var diagnostic in result.Diagnostics)
        Console.Error.WriteLine(diagnostic);
}

Configuration paths are resolved relative to bridge.json. The bridge output contains C-facing headers, src/Classes.cpp, and a deterministic bridge.manifest.json with target, source, include, definition, compiler/linker, language-standard, and library inputs. The BindGen-CS tool can compile this manifest with native-build; embedded consumers can use ClangNativeBuildProvider and NativeBuildExecutor directly.

Verified bridge scope

The regression suite covers constructors/destructors, instance and static methods, overloads, namespace functions, exception boundaries, pointer-adjusting multiple inheritance, explicit class and function template instances, std::string, std::vector, std::span, std::array, std::map, std::set, std::optional, std::variant, std::expected, std::filesystem::path, std::chrono, std::unique_ptr, std::shared_ptr, and configured pure-virtual callback proxies.

Unknown template specializations and undeclared ownership or allocator contracts remain explicit boundaries. VerifiedOnly rejects project-supplied assumptions. AllowUserAsserted accepts reviewed project contracts. AllowUnsafe continues with an auditable BGCS-SAFETY-LOWERING-BYPASS warning; it transfers risk but cannot make an unrepresentable ABI valid.

Documentation

BindGen-CS is licensed under the MIT License. Portions derived from CppAst/HexaGen retain their original notices.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.4 41 9/26/2026
2.0.3 42 9/25/2026
1.0.1 126 4/9/2026
1.0.0 114 4/9/2026
1.0.0-alpha.1 67 4/6/2026