linking to C libraries

Bill Baxter dnewsgroup at billbaxter.com
Wed Dec 5 13:17:13 PST 2007


aeschere wrote:
> I am trying to use D in more of my everyday programming (utility
> programming at the moment).  However, quite often I need to link to
> various C libraries (for example pcap).  Does D support linking to C
> libraries?  If it does, are there special concerns that I need to be
> aware of?
> 
> Thank you in advance for your time,

D does support linking to C.  The main caveat is that if you're using 
the DMD compiler on Windows you will need to compile the C library with 
DMC (the Digital Mars C compiler).  This is because DMD/DMC only support 
compiled code and libraries in the OMF format, whereas Visual Studio and 
MinGW generate COFF.

The other option is if the C code is in a DLL on Windows, then you can 
create a DMD-compatible import lib from it using the 'implib' program 
from the free "Basic Utilities Package" (BUP):
* http://www.digitalmars.com/ctg/implib.html
* http://ftp.digitalmars.com/bup.zip


On linux DMD uses ELF like other linux compilers, so I think it's easier 
there.

There's a whole different set of answers to this question if you're 
using GDC.  This sounds like a good topic for a FAQ page somewhere on 
the wiki.

--bb


More information about the Digitalmars-d-learn mailing list