# Generate C APIs

**URL:** https://discourse.vtk.org/t/generate-c-apis/15886
**Category:** Support
**Tags:** c
**Created:** [July 31, 2025, 1:58am UTC](https://discourse.vtk.org/t/generate-c-apis/15886 "2025-07-31T01:58:46Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Nikon\_Sugar](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nikon_sugar/32/10167_2.png) [@Nikon\_Sugar](https://discourse.vtk.org/u/Nikon_Sugar)
#### Post date: [July 31, 2025, 1:58am UTC](https://discourse.vtk.org/t/generate-c-apis/15886/1 "2025-07-31T01:58:46Z")

</div>

I was wondering how to generate C APIs using `wrapping` tool. The idea is that C APIs can be based to create binding to other languages such as Rust, Zig. Any guide with coding snippet would be appreciated. Thank you!

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [July 31, 2025, 2:31pm UTC](https://discourse.vtk.org/t/generate-c-apis/15886/2 "2025-07-31T14:31:06Z")

</div>

There have been discussions about generating C bindings, but no movement.

Personally, my primary interest is in using them for Python bindings so that the Python wrappers can “just” do `cffi` and be far more Python-version-independent.

Cc: @dgobbi @jaswantp @berk.geveci

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [July 31, 2025, 2:38pm UTC](https://discourse.vtk.org/t/generate-c-apis/15886/3 "2025-07-31T14:38:51Z")

</div>

I’ll plug my [WrapVTK](https://github.com/dgobbi/WrapVTK) project once again. It doesn’t generate C bindings, but it generates a full XML description of the VTK C++ API, including full API documentation from the doxygen comments in the headers.

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [July 31, 2025, 2:43pm UTC](https://discourse.vtk.org/t/generate-c-apis/15886/4 "2025-07-31T14:43:00Z")

</div>

That’d be cool, but I’ll say this.

This may not be the answer your are looking for but there is a [C API](https://vtk.org/doc/nightly/html/vtkSession_8h.html#details) to create and modify few select VTK objects listed [here](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Utilities/Marshalling/VTK_MARSHALAUTO.txt) and [here](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Utilities/Marshalling/VTK_MARSHALMANUAL.txt) .

The downside is that they not super efficient since it uses json strings to set/get property values and transform function arguments and return values. As a result, all the properties, function args, etc must be passed in as JSON strings.

---

<div class="post-metadata">

### Author: ![berk.geveci](https://discourse.vtk.org/user_avatar/discourse.vtk.org/berk.geveci/32/3146_2.png) [@berk.geveci](https://discourse.vtk.org/u/berk.geveci)
#### Post date: [July 31, 2025, 2:50pm UTC](https://discourse.vtk.org/t/generate-c-apis/15886/5 "2025-07-31T14:50:26Z")

</div>

This would be very useful for generating Julia bindings also. If someone from Kitware has time to investigate the level of effort involved before September 30th, I can provide a resource. Efficiency is somewhat important, but probably not super critical, since we usually pass large data structures as arrays. Parity with the existing wrappers is super critical.

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [August 1, 2025, 12:30am UTC](https://discourse.vtk.org/t/generate-c-apis/15886/6 "2025-08-01T00:30:17Z")

</div>

Activiz already does this!

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 1, 2025, 12:32am UTC](https://discourse.vtk.org/t/generate-c-apis/15886/7 "2025-08-01T00:32:07Z")

</div>

Doesn’t Activiz provide C# interface? I did not know it also had C API.

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [August 1, 2025, 12:32am UTC](https://discourse.vtk.org/t/generate-c-apis/15886/8 "2025-08-01T00:32:42Z")

</div>

The C# assemblies pinvoke the C dll API.

Of course the generation of those DLLs is horribly coupled into the project generation via CMake.

---

<div class="post-metadata">

### Author: ![Nikon\_Sugar](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nikon_sugar/32/10167_2.png) [@Nikon\_Sugar](https://discourse.vtk.org/u/Nikon_Sugar)
#### Post date: [August 1, 2025, 12:39am UTC](https://discourse.vtk.org/t/generate-c-apis/15886/9 "2025-08-01T00:39:35Z")

</div>

link to the detail please?

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [August 1, 2025, 12:47am UTC](https://discourse.vtk.org/t/generate-c-apis/15886/10 "2025-08-01T00:47:22Z")

</div>

Activiz is no longer open source and Kitware has removed all links about how to build the legacy code for VTK 5.8.

The code looks like this from _ **vtkPolygonEL.cxx** _

```auto
//----------------------------------------------------------------------------
//
// This file was machine generated by:
// mummy version 1.0.3 (revision 599)
//
// Manual changes to this file may be overwritten by the next build.
//

//----------------------------------------------------------------------------
// You can use this symbol in your header files if there are bits of your
// code that should be conditionally compiled in this export layer.
//
#define MUMMY_EXPORT_LAYER_CXX

//----------------------------------------------------------------------------
// Do not emit the silly C4996 warning for strncpy use:
//
#ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE
#endif

//----------------------------------------------------------------------------
// Forward declare functions that generated code might call...
//
#ifdef _WIN64
extern "C" __declspec(dllimport) void*__stdcall CoTaskMemAlloc(unsigned __int64 cb);
#define MUMMY_STRING_ALLOC ::CoTaskMemAlloc
#else
#ifdef _WIN32
extern "C" __declspec(dllimport) void*__stdcall CoTaskMemAlloc(unsigned long cb);
#define MUMMY_STRING_ALLOC ::CoTaskMemAlloc
#endif
#endif

#ifndef MUMMY_STRING_ALLOC
#define MUMMY_STRING_ALLOC malloc
#endif

//----------------------------------------------------------------------------
// Macro for exporting functions implemented in this file...
//
#ifdef _WIN32
#define MUMMY_DLL_EXPORT __declspec(dllexport)
#else
#define MUMMY_DLL_EXPORT
#endif

//----------------------------------------------------------------------------
#include "C:/Users/toddm/workspace/3RD_PARTY/VTK-8.1/vtk/Common/DataModel\vtkPolygon.h"

//----------------------------------------------------------------------------
#include "MummyRuntime.h"
#include "string.h" // for possible memset use
#include "vtkObjectBase.h"

//----------------------------------------------------------------------------
extern "C" MUMMY_DLL_EXPORT
vtkPolygon* vtkPolygon_New(unsigned int* mteStatus, unsigned int* mteIndex, unsigned int* rawRefCount)
{
   vtkPolygon* rv = 0;

   rv = vtkPolygon::New();
   if (0 != rv)
      {
      vtkObjectBase* ro = (vtkObjectBase*) (void*) rv;
      Kitware::mummy::TypeEntry* entry = Kitware::mummy::Runtime::GetTypeEntry(
         (void*) rv, typeid(*ro).name());
      *mteStatus = 0;
      *mteIndex = entry->GetIndex();
      *rawRefCount = (unsigned int) ro->GetReferenceCount();
      }

   return rv;
}

//----------------------------------------------------------------------------
extern "C" MUMMY_DLL_EXPORT
void vtkPolygon_SetUseMVCInterpolation_40(vtkPolygon* pThis, bool _arg)
{
   pThis->SetUseMVCInterpolation(_arg);
}

//----------------------------------------------------------------------------
extern "C" MUMMY_DLL_EXPORT
int vtkPolygon_Triangulate_42(vtkPolygon* pThis, vtkIdList* outTris)
{
   int rv = 0;

   rv = pThis->Triangulate(outTris);

   return rv;
}

```

---

<div class="post-metadata">

### Author: ![Nikon\_Sugar](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nikon_sugar/32/10167_2.png) [@Nikon\_Sugar](https://discourse.vtk.org/u/Nikon_Sugar)
#### Post date: [August 1, 2025, 1:18am UTC](https://discourse.vtk.org/t/generate-c-apis/15886/11 "2025-08-01T01:18:53Z")

</div>

Quick pivot with [WrapVTK](https://github.com/dgobbi/WrapVTK) generated xml then fed into AI coding tool for a single file `vtkImageViewer2`, seem to be promising, not sure about its consistency though. Link to generated code here:

- [c header, c++ implementation and zig bindings](https://claude.ai/public/artifacts/6d4d8864-d9aa-43fe-b2bf-378a7cdebb47)
- [c++ implementation](https://claude.ai/public/artifacts/4c421520-ae5f-4289-8d49-f3a5e555d46e)
- [zig binding](https://claude.ai/public/artifacts/9e453ebe-9524-4235-930e-0885d7e962cb)

---

<div class="post-metadata">

### Author: ![Nikon\_Sugar](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nikon_sugar/32/10167_2.png) [@Nikon\_Sugar](https://discourse.vtk.org/u/Nikon_Sugar)
#### Post date: [August 1, 2025, 1:20am UTC](https://discourse.vtk.org/t/generate-c-apis/15886/12 "2025-08-01T01:20:38Z")

</div>

any latest unofficial oss code that we can try?

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 1, 2025, 12:32pm UTC](https://discourse.vtk.org/t/generate-c-apis/15886/13 "2025-08-01T12:32:14Z")

</div>

Good, the generated C wrapping looks like what I’d expect. Using WrapVTK would be robust for this. There is no oss code that creates C wrappings of vtk classes afaik.

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [August 1, 2025, 11:52pm UTC](https://discourse.vtk.org/t/generate-c-apis/15886/14 "2025-08-01T23:52:04Z")

</div>

The open source version of _Activiz_ used _Mummy_ ([GitHub - gccxml/mummy](http://github.com/gccxml/mummy)) with _CableSwig_ ([GitHub - gccxml/CableSwig](http://github.com/gccxml/CableSwig)) to produce the wrapper code.

It depends on _gccxml_ which is really old so I modified the repository here [GitHub - todoooo/mummy](https://github.com/todoooo/mummy) to use _CastXML_ ([GitHub - CastXML/CastXML: C-family Abstract Syntax Tree XML Output](http://github.com/CastXML/CastXML)) instead.

I also made some minor changes to _CableSwig_ here [GitHub - todoooo/CableSwig](http://github.com/todoooo/CableSwig).

@Nikon_Sugar If AI can produce suitable bindings from XML then probably _CastXML_ is all you need. Here’s the xml output for vtkPolygon. [vtkPolygon.xml](https://discourse.vtk.org/uploads/short-url/9C9RSarGjZCH7QyuPY8DI1Lz9L.xml) (88.1 KB)  
See if it provides a useful starting point for AI code generation.

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [August 4, 2025, 11:40pm UTC](https://discourse.vtk.org/t/generate-c-apis/15886/15 "2025-08-04T23:40:37Z")

</div>

The original repository for Activiz hosted by Kitware has gone but I found a mirror [GitHub - dlrdave/activizdotnet: Periodically updated mirror of git://public.kitware.com/activizdotnet.git](http://github.com/dlrdave/activizdotnet)
