How do I use my c/c++ libraries in D?

JohnC johnch_atms at hotmail.com
Tue Dec 19 05:22:27 PST 2006


"Stan Hebben" <stanhebben at gmail.com> wrote in message 
news:em8mjr$21j5$1 at digitaldaemon.com...
>I have a lot of questions about using my c/c++ libraries in d.
> - How does the compiler 'map' the c libraries to d modules? (ex. if I 
> write
> 'import std.c.stdio', where does the compiler look for this file)

D doesn't compile C/C++ files. std.c.stdio is actually a D import module.

Packages such as std.c generally map to a directory structure. In this case, 
the path is dmd\src\phobos\std\c\stdio.d. The compiler also reads sc.ini in 
the dmd\bin folder to determine where to look for import libraries - for 
instance, "-I..\..\src\phobos".

> - Does the D compiler use C header files, or header files which are 
> converted
> to D?

The latter. There's a utility called htod 
http://www.digitalmars.com/d/htod.html that attempts to generate a D module 
from a C header.

>
> I mainly want to use the Windows / DirectX API in D, as well as some other
> libraries.

The WindowsAPI project on DSource has translations of many of the SDK 
headers, including DirectX. 
http://www.dsource.org/projects/bindings/browser/trunk/win32

Check out DSource for other libraries that have been ported to D. If you 
don't find what you need there, there's the aforementioned htod. But it's 
not that difficult to translate C headers by hand - just tedious... Issues 
to watch out for include macro expansions and bit fields.

>
> I suppose this question has been asked many times, but I couldn't find it 
> on
> the forums. (neither did I find my answer somewhere else on the web) 




More information about the Digitalmars-d-learn mailing list