Thread overview
How do I use my c/c++ libraries in D?
Dec 19, 2006
Stan Hebben
Dec 19, 2006
Don Clugston
Dec 19, 2006
Lutger
Dec 19, 2006
JohnC
December 19, 2006
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)
- Does the D compiler use C header files, or header files which are converted
to D?

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

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)
December 19, 2006
Stan Hebben wrote:
> 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)
> - Does the D compiler use C header files, or header files which are converted
> to D?

Headers converted to D. The ctod program from the digital mars site will  do an automatic conversion for you. You also need the coffimplib program to convert the .lib files from Microsoft/COFF format into OMF format.

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

Look on www.dsource.org in the 'bindings' project, several have already been converted.

> 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)
December 19, 2006
Stan Hebben wrote:
> 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)

The standard C library is included in the runtime, see dmd\src\phobos\std\c for declarations.

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

Headers files which are converted to D. See http://www.digitalmars.com/d/htomodule.html for converting header files to D. There is also a tool which can do a lot automatically: http://www.digitalmars.com/d/htod.html

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

Take a look at www.dsource.org if you have not done already, chance is that there is already a binding. The wiki4d may also have more links to bindings. A set of bindings for win32 is here: http://www.prowiki.org/wiki4d/wiki.cgi?WindowsAPI

I have seen some directx bindings somewhere, but don't remember where they are.

> 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)
December 19, 2006
"Stan Hebben" <stanhebben@gmail.com> wrote in message news:em8mjr$21j5$1@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)