Simplest way to build a DMD compatible C lib, and how to link using DUB.
Mike Parker via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Dec 14 19:47:27 PST 2016
On Wednesday, 14 December 2016 at 23:08:30 UTC, hardreset wrote:
> I built Freetype with MSVC13 and tried to link it but DMD didnt
> like the format, so what should compiler (free) should I use
> for building DMD compatible static libs?
The MS linker produces COFF format. By default, DMD uses the
OPTLINK linker, which only understands OMF. Assuming DMD is
configured to find your MSVC installation, you can link directly
with COFF libraries and objects by passing -m64 or -m32mscoff on
the DMD command line. With DUB, use -ax86_64 on the command line
to make it use -m64. Unfortunately, there is currently no such
option for it to use -m32mscoff, so you need to configure it in
your dub configuration with a "dflags" directive and make sure
any dependencies are compiled that way as well.
>
> Once I've build the lib, made a di file, where do I put these
> things in the dub directory structure?
Where ever you want. If you put the di file in your source
directory, DUB will pick it up automatically. For libraries, I
usually put them in a 'lib' subdirectory and add this in the
module with my main method:
version(Windows) pragma(lib, `lib\foo.lib`);
As Basile recommended, DerelictFT[1] will save you from the
hassle of object formats. It's a dynamic binding, so you don't
need to link with FreeType at all during compilation. You simply
call DerelictFT.load during initialization and it will load the
FreeType DLL for you. However, if your goal is to use DLLs, then
you either have to use the MS linker as I described above or get
FreeType into the OMF format (either by compiling with DMC or
using an object converter).
[1] https://github.com/DerelictOrg/DerelictFT
More information about the Digitalmars-d-learn
mailing list