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
- TracGuide -- Built-in Documentation
For a complete list of local wiki pages, see TitleIndex.