How do I interface D to a C library based on a DLL?
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Wed Jun 13 03:05:03 PDT 2007
Christopher Grantham wrote:
> Sorry, should have included the 'test.d' file...very n00bish, but its
> the most simple way to know the API library is working:
>
> #!J:/dmd/bin/dmd.exe -run
>
> import std.stdio;
> import std.c.windows.windows;
>
> import OrcFxAPI;
[snip]
>
> As you can see, I'm assuming the converted header becomes a D module
> with the filename as the module name (minus the '.d' extension)...
> I'm probably going about it all wrong or something, so feel free to
> correct me, I could use the constructive criticism...
The naming of the converted header doesn't matter much, though
consistency with the C name is probably a good thing.
You may want to post your OrcFxApi.{h,d} files (or links to them) if you
need help translating.
Or you could just see if bcd (http://dsource.org/projects/bcd) can
translate it automatically.
At first glance, since the errors you get are all "Previous Definition
Different", I'd guess you were compiling your translated header and
linking to it. And you're not using extern {} to stop inclusion of
symbols already defined in the actual library.
If you're using a raw command line, not compiling your module at all may
work (if everything needed to use it can be linked in from the C library).
If you're using (re)build, putting "version(build) pragma(nolink);" in
the .d file or renaming it to .di may do the trick.
Otherwise, try wrapping your translated header (except any #defines
translated to constants or functions) in an "extern {}" (as well as the
normal "extern(C) {}").
If none of the above works, post your .h and .d/.di files and someone
may be able to help.
More information about the Digitalmars-d-learn
mailing list