The c2hsc package

[Tags:bsd3, program]

Convert C API header files to .hsc and .hsc.helper.c files

[Skip to Readme]


Versions 0.1.0, 0.2.0, 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.4.0, 0.5.0, 0.5.1, 0.6.2, 0.6.3, 0.6.4, 0.6.5
Dependencies base (==4.*), cmdargs, containers, directory, filepath, HStringTemplate, language-c, mtl, pretty, transformers [details]
License BSD3
Author John Wiegley
Maintainer John Wiegley <>
Category Utilities
Home page
Source repository head: git clone
Uploaded Wed Sep 5 08:07:38 UTC 2012 by JohnWiegley
Distributions NixOS:0.6.5
Downloads 3207 total (20 in the last 30 days)
0 []
Status Docs not available [build log]
Last success reported on 2016-12-24 [all 8 reports]


Maintainer's Corner

For package maintainers and hackage trustees

Readme for c2hsc

Readme for c2hsc-0.3.0

Converts C API header files to .hsc and .hsc.helper.c files

Usage: c2hsc <Lib Prefix> [cpp options...] <FILE>.h

This will create <FILE>.hsc, and <FILE>.hsc.helper.c if the header file contains inline functions.

For example, in hlibgit2 on the Mac I'm using:

c2hsc Bindings.Libgit2 -U__BLOCKS__ libgit2/include/git2/tree.h

Known issues:

  • Varargs functions do not translate
  • Arrays are not handled at all (use #array_field $name , $type)
  • Handle type synonyms
  • Unnamed enums are not being emitted
  • Inline helper generator outputs the wrong headers
  • Files named foo_bar should become FooBar
  • Global variables are not being emitted

Also, please note that this tool will never be 100% accurate. It cannot translate macros, or anything related to the preprocessor, for example. It often misses necessary #include files, and will get them wrong in any case if preprocessor conditionals are involved.

The goal of c2hsc is to solve the hardest 80% of the problem of creating an FFI library. The remaining 20%, plus validation of the results, is an exercise necessarily left to the user.