Linking C library (.dll) to D on windows
Roman via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jan 25 12:45:38 PST 2015
Stuff:
1. There are C code module.c and module.h
2. MinGW
3. DMD 2.066.1
4. Window 8.1
module.c:
#include "module.h"
int add(int a, int b) {return a + b;}
module.h:
int add(int,int);
I want to use function "add" from D
so i call
> cc -shared module.c -o module.dll
Then D code
main.d:
import std.stdio;
extern(C)
{
int add(int a, int b);
}
void main()
{
writefln("From C Dll %d",add(2,3));
}
So how i should compile with dmd, to get this work?
> dmd main.d -L=module.dll
prints:
OPTLINK (R) for Win32 Release 8.00.15
Copyright (C) Digital Mars 1989-2013 All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Error 8: Illegal Filename
main,,nul,user32+kernel32/noi=module.dll;
^
--- errorlevel 1
I've tried to found smthing here
http://wiki.dlang.org/Compiling_and_linking_with_DMD_on_Windows
but dll tutorial is missing
So does DMD available to link dll files?
More information about the Digitalmars-d-learn
mailing list