Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.
Version 4 (modified by Gregor, 18 years ago)
--

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, therefore requir 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.

Howto

First, you will need gccxml installed. Its homepage is http://www.gccxml.org/ . You will probably need the CVS version.

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

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)

Example

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

Starting Points

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

Attachments

  • 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.