How to call a function from a dll created with d ?

Vinod KC kcvinu82 at gmail.com
Fri Jul 1 19:11:16 UTC 2022


Hi all,
I have created a dll file with this code.
```d
module dimedll;
import core.sys.windows.windows;
import core.sys.windows.dll; // I don't what is this for.
import std.stdio;


mixin SimpleDllMain;

export void testFunc() {
     writeln("This is from dll");
}
```
So now I have a dll fie named `dimedll.dll` and a lib file named 
`dimedll.lib`.
Now, I have created a d source file called `dime.d` and wrote 
this code.
```d
import std.stdio;
import core.sys.windows.windows;
import std.stdio : log = writeln;

pragma(lib, "dimedll.lib");

extern void testFunc();

void main() { 	
	log("Lets build our own ime");
	testFunc();		
}
```
Everything seems to be okay. So I called dmd with this command.
`dmd -i -run dime.d`
But I got this error message.
```
dime.obj : error LNK2019: unresolved external symbol 
__D4dime8testFuncFZv referenced in function __Dmain
dime.exe : fatal error LNK1120: 1 unresolved externals
Error: linker exited with status 1120```
How to fix this ?


More information about the Digitalmars-d-learn mailing list