Linking C libraries with DMD
jmh530 via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jan 21 08:14:40 PST 2016
I'm trying to understand calling C libraries from D on Windows
with DMD. I made a simple example and compiled it with a static
library fine (so I've converted the .h file correctly). Then, I
compiled with gcc to a shared library (because I cannot for the
life of me figure out how to do this with DMC). I then used
implib to generate a .lib file (the fact that this is necessary
is not described nearly well enough in the documentation).
The next step is getting this to compile with dmd. I'm getting an
error that the function isn't getting called, which is suggesting
that I'm not linking the .lib file with DMD properly.
The dmd page
https://dlang.org/dmd-windows.html
explains that -L is used to pass stuff to the linker. It seems to
indicate that this should be the folder that the library is in.
The dll and lib files are in the same folder as the .d file I'm
trying to compile. So presumably, this should be -L. or -L\. or
like -LC:\folder\. But nothing like that works. There's a link on
the dmd page to optlink, which doesn't really help me figure this
out either. There's also some stuff about set LIB in the sci.ini.
Not sure I'm supposed to mess with that.
The LearningD book has some examples as well. I don't have it in
front of me right now, but I think I tried what they recommend
also. Nevertheless, I feel like the documentation should be clear
enough so that this isn't so frustrating.
More information about the Digitalmars-d-learn
mailing list