Note: This website is archived. For up-to-date information about D projects and development, please visit

Welcome to BCD

BCD stands for Bindings to C(++) in D. Its most notable component is bcd.gen, which generates C or C++ bindings from .h files.

Generated C++ bindings replicate the API of the underlying C++ code, but have a C layer as a gobetween, and therefore require both a D compiler and a C++ compiler.

Generated C bindings are simply extern (C)'s and structs, and therefore only require a D compiler.

Project Status

Development seems to have stalled with changeset 127 on 03-17-2008.

Related Efforts

These are some tools that could be helpful in using C/C++ code in a D project:

Getting the source

To get the latest version of bcd.gen:

svn co

To get the latest BCD bindings:

svn co

Windows Binary

If you're using Windows and you don't want to compile it yourself, you can try this Windows binary:



You will need gccxml installed. Its homepage is . You will probably need the CVS version.

You will also need libxml2. Its homepage is


To compile bcdgen, just make in the root directory, or make DMD=gdmd to use GDC.


Any variables in CXXFLAGS (or CFLAGS for generating C bindings) will be picked up by gccxml in the bcd.gen process. So, you will probably need to add the flags for your tool to the environment variable. In bash, for example, you can do that like so:

export CXXFLAGS="$CXXFLAGS `some-config --cxxflags`"

To create a binding, do:

./bcdgen <header file> <D namespace> [-C] [-A] [-I<include prefix>] [other options]

The D namespace is under bcd., so if you use the namespace 'fltk2', for example, the D interfaces will be in bcd.fltk2.*.

-C puts bcd.gen in C mode instead of C++ mode.

-A causes bcd.gen to output all symbols, not just those in the header file specified, which is most useful for metaheaders which #include a number of other ones.

-I changes the #include line in the output C++ file (if you're using C++) to put the specified prefix before the filename.

Note that the generated bindings rarely work immediately, but will require some minor tweaking. Most notably:

  • If the header uses structs that are never actually defined, you will need to add the definition. If it only uses pointers, you can add an empty stub definition.
  • If the header uses struct timeval, you'll have to import std.socket (I blame this oversight on Windows)
  • If you use -A, it may generate unnecessary import lines which will need to be removed (a bug I'm working on)

Current Bindings

BCD is not only a binding generator, but a collection of bindings generated with it. The current bindings are:

  • curses (C)
    • By request. Untested. If you use this binding, please post reports here.
  • fltk2 (C++)
    • The example binding, a really well-bound C++ library. Has the exact same interface in D as in C++ :)
  • gd2 (C)
    • By request. Untested. If you use this binding, please post reports here.
  • gtk+ (C)
    • (And friends: atk, cairo, gdk, glib2, pango)
    • It works great. Don't use it. That's what duit is for :)
  • libevent (C)
    • By request. Untested. If you use this binding, please post reports here.
  • libxml2 (C)
    • Actually used by the generator itself ... recursive dependencies are good for you.
  • ogg, vorbis (C)
    • Untested except for a basic example program, please post reports here.
  • tiff (C)
    • By request. Untested. If you use this binding, please post reports here.


I'm using FLTK2 as an example binding, so you'll find incomplete bindings to it in bcd/fltk2


bcd.gen was written, for the most part, by Gregor Richards. His home page is

Starting Points

For a complete list of local wiki pages, see TitleIndex.


  • fltk.png (1.9 kB) -A ridiculously simple screenshot of FLTK2 from D., added by Gregor on 05/28/06 22:26:07.
  • gtk2.png (2.9 kB) -Example use of BCD-generated GTK+2 binding, added by Gregor on 05/31/06 22:59:19.