www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Linking C Headers to D

reply DRex <armstronga94 hotmail.com> writes:
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.
Jan 11 2017
parent Mike Parker <aldacron gmail.com> writes:
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
Jan 11 2017