How to call a function from a dll created with d ?
Ruby The Roobster
rubytheroobster at yandex.com
Fri Jul 8 03:20:23 UTC 2022
On Saturday, 2 July 2022 at 20:43:41 UTC, Vinod KC wrote:
> On Saturday, 2 July 2022 at 14:32:11 UTC, apz28 wrote:
>>
>> dmd -of=dimedll.dll dimedll.d dimedll.def
>> dmd dime.d dimedll.di
>
> Thanks for the reply. Well, I am sorry to say that your
> suggestions resulted in failure.
> First of all, when I used this command -- ` dmd -of=dimedll.dll
> dimedll.d dimedll.def` I got this error message-
> `Error: unrecognized file extension dll`.
> So I avoided the `-of=dimedll.dll` part.
> Then I compiled it with this command - `dmd -H dimedll.d
> dimedll.def`
> And I got some warnings. Here are they.
> ```d
> dimedll.def(2) : warning LNK4017: EXETYPE statement not
> supported for the target platform; ignored
> dimedll.def(3) : warning LNK4017: SUBSYSTEM statement not
> supported for the target platform; ignored
> dimedll.def(4) : warning LNK4017: CODE statement not supported
> for the target platform; ignored
> dimedll.def(4) : warning LNK4017: DATA statement not supported
> for the target platform; ignored
> Creating library dimedll.lib and object dimedll.exp
> ```
> I know all of them are from my `def` file. Anyways, I stepped
> forward and tried to run the main file with this dll & lib.
> So I ran this command. - `dmd dime.d dimedll.di`. But I got
> this error message.
> ```d
> dime.obj : error LNK2001: unresolved external symbol
> __D7dimedll12__ModuleInfoZ
> dime.exe : fatal error LNK1120: 1 unresolved externals
> Error: linker exited with status 1120
> ```
First issue - you're using dmd on windows. Dmd gives me errors
about the ModuleInfo, while LDC doesn't. [This is the LDC
download
link.](https://github.com/ldc-developers/ldc/releases/download/v1.29.0/ldc2-1.29.0-windows-multilib.exe) Next, change dimedll.d to the following:
```d
module dimedll;
export void testFunc()
{
import std.stdio;
writeln("Lets build our own ime.");
}
```
and dime.d to the following:
```d
import dimedll; //In case you ever write more functions for
dimedll.d;
pragma(lib, "dimedll.lib");
void main()
{
testFunc();
}
```
Then run ```ldc2 -shared dimedll.d``` and right after that
```ldc2 dime.d```. If I didn't make a mistake in writing this (I
tested it on my own system), it should output a working program
that prints the expected output when ran.
More information about the Digitalmars-d-learn
mailing list