Linking C libraries with DMD
Dibyendu Majumdar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jan 21 14:54:26 PST 2016
On Thursday, 21 January 2016 at 22:49:06 UTC, jmh530 wrote:
>
> I'm not trying to created a shared library in D. My goal is to
> use a shared library from C in D. Right now, I'm working with a
> simple test case to make sure I could understand it before
> working with the actual shared library I want to use.
>
> I recall some discussion in LearningD (don't have it in front
> of me now) that different types of shared libraries are needed
> on 32bit vs. 64bit because there is a different linker. This is
> what I did to created the shared library:
>
> gcc -Wall -fPIC -c <file>.c -I.
> gcc -shared -o <libfile>.dll <file>.o -I.
> implib <libfile>.lib <libfile>.dll
Okay then you don't need the /IMPLIB option. But you do need to
specify the library via -L as I mentioned before.
i.e. use:
dmd -m64 -L/LIBPATH:<path to lib> -L<library name> prog.d
Where <library name> is yourlib.lib and this is present along
with the DLL in the path you gave.
Plus your prog.d needs to have appropriate code. Example:
module app;
extern (C) void testing();
void main()
{
testing();
}
Here testing() is provided in the DLL.
More information about the Digitalmars-d-learn
mailing list