Linking C Headers to D
Mike Parker via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 11 21:07:31 PST 2017
On Thursday, 12 January 2017 at 04:54:18 UTC, DRex wrote:
> Hi,
>
> I am trying to link C and D (using GCC and GDC) and I am
> wondering (I could find no answers on google) if it is possible
> to compile C headers into object files and link them to D? I
> have a large code base of C headers and am not at a point where
> I can translate them all to D in one go, so I need to be able
> to link to the headers.
>
> Thanks.
You can't compile headers. You compile source files. Do that, and
yes, you can link object files and libraries with your compiled D
code. D uses the same file formats and linkers as C.
However, the D compiler needs to know what symbols are available
for you to use on the C side, so you any C functions you want to
call and types you want to use have to be translated to D. You
can do it manually or use a tool like DStep to do the bulk of the
work for you. See the links in the forum post at [1] for more
info.
[1] http://forum.dlang.org/post/o55cie$2vb8$1@digitalmars.com
More information about the Digitalmars-d-learn
mailing list