Version 7 (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.
Getting the source
To get the latest version of bcd.gen:
svn co http://svn.dsource.org/projects/bcd/trunk/bcd.gen
To get the latest BCD bindings:
svn co http://svn.dsource.org/projects/bcd/trunk/bindings
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)
Current Bindings
BCD is not only a binding generator, but a collection of bindings generated with it. The current bindings are:
- fltk2 (C++)
- The example binding, a really well-bound C++ library. Has the exact same interface in D as in C++ :)
- 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.
Example
I'm using FLTK2 as an example binding, so you'll find incomplete bindings to it in bcd/fltk2
Starting Points
- TracGuide -- Built-in Documentation
For a complete list of local wiki pages, see TitleIndex.