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

2022-07-08 Thread frame via Digitalmars-d-learn
On Thursday, 7 July 2022 at 17:29:42 UTC, cc wrote: Does importing dimedll into app.d properly NOT link in the functions that are exported to the DLL? When I tried something similar with dmd, I had to create a .di file containing just stubs, otherwise it looked like it was ignoring the DLL

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

2022-07-07 Thread Ruby The Roobster via Digitalmars-d-learn
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

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

2022-07-07 Thread cc via Digitalmars-d-learn
On Sunday, 3 July 2022 at 09:43:20 UTC, frame wrote: app.d: ```d module app; import dimedll; import std.stdio; import std.stdio : log = writeln; pragma(lib, "dimedll.lib"); void main() { log("Lets build our own ime"); testFunc(); } ``` You should be able to change contents

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

2022-07-04 Thread frame via Digitalmars-d-learn
On Sunday, 3 July 2022 at 16:48:52 UTC, frame wrote: Only the -H switch or manual linker command generates a valid link to the DLL with DMD but then it's missing all the other library contents (also it needs `SimpleDllMain` or bails out linking errors to `_calloc` and Windows symbols) :\

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

2022-07-03 Thread frame via Digitalmars-d-learn
On Sunday, 3 July 2022 at 12:54:45 UTC, kinke wrote: On Sunday, 3 July 2022 at 08:15:38 UTC, frame wrote: Are you sure? 100%, just try yourself. Why would the symbol be defined in the executable? `dimedll.d` isn't compiled into the executable. The code is using Phobos std.stdio.writeln

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

2022-07-03 Thread kinke via Digitalmars-d-learn
On Sunday, 3 July 2022 at 08:15:38 UTC, frame wrote: Are you sure? 100%, just try yourself. You import `testFunc` as normal import, the compiler ignores `pragma(lib)` - that's only for the linker which will ignore it too since the symbol is already in your executable. Why would the symbol

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

2022-07-03 Thread frame via Digitalmars-d-learn
On Saturday, 2 July 2022 at 20:43:41 UTC, Vinod KC wrote: But I got this error message. dime.obj : error LNK2001: unresolved external symbol __D7dimedll12__ModuleInfoZ dime.exe : fatal error LNK1120: 1 unresolved externals Error: linker exited with status 1120 I tried the -H switch. You

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

2022-07-03 Thread frame via Digitalmars-d-learn
On Saturday, 2 July 2022 at 14:06:03 UTC, kinke wrote: With LDC, this is sufficient for this trivial example: ```d module dimedll; export void testFunc() { // export only needed when compiling with `-fvisibility=hidden` import std.stdio; writeln("This is from dll"); } ``` `ldc2

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

2022-07-02 Thread Vinod K Chandran via Digitalmars-d-learn
On Saturday, 2 July 2022 at 21:36:50 UTC, mw wrote: Actually, can you create a github repo, I'm sure people will send you a working PR. Yes I can. I will inform here once I did it.

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

2022-07-02 Thread mw via Digitalmars-d-learn
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

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

2022-07-02 Thread Vinod KC via Digitalmars-d-learn
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

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

2022-07-02 Thread apz28 via Digitalmars-d-learn
Below is working on Windows --file dimedll.d: module dimedll; import core.sys.windows.windows; import core.sys.windows.dll; import std.stdio; mixin SimpleDllMain; export void testFunc() { writeln("This is from dll"); } --file dime.d: import core.sys.windows.windows;

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

2022-07-02 Thread kinke via Digitalmars-d-learn
With LDC, this is sufficient for this trivial example: ```d module dimedll; export void testFunc() { // export only needed when compiling with `-fvisibility=hidden` import std.stdio; writeln("This is from dll"); } ``` `ldc2 -shared dimedll.d` generates import lib + DLL. ```d import

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

2022-07-02 Thread Vinod K Chandran via Digitalmars-d-learn
On Saturday, 2 July 2022 at 01:05:25 UTC, Ali Çehreli wrote: 3) The users of this dll should import that .di file (declaring the functions themselves won't work): Ali Hi, Thanks for the reply. I have tried your suggestion. First, I compiled my dll's source code with `-H` switch as you

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

2022-07-01 Thread Ali Çehreli via Digitalmars-d-learn
On 7/1/22 12:11, Vinod KC wrote: The following function is dimedll.testFunc: > ```d > module dimedll; // ... > export void testFunc() { > writeln("This is from dll"); > } > ``` We suspect the name of the file that defines main() is dime.d. > extern void testFunc(); That symbol belongs

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

2022-07-01 Thread Vinod KC via Digitalmars-d-learn
On Saturday, 2 July 2022 at 00:23:20 UTC, Ruby The Roobster wrote: The solution is to remove the extern declaration. That does it for me, and it prints the expected output. No need for a .def file, unless you are using optlink as your linker (which, as a matter of principle, you should use

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

2022-07-01 Thread Ruby The Roobster via Digitalmars-d-learn
The solution is to remove the extern declaration. That does it for me, and it prints the expected output. No need for a .def file, unless you are using optlink as your linker (which, as a matter of principle, you should use lld or ld instead.)

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

2022-07-01 Thread Vinod K Chandran via Digitalmars-d-learn
On Friday, 1 July 2022 at 22:38:17 UTC, Adam D Ruppe wrote: On Friday, 1 July 2022 at 22:32:24 UTC, Vinod K Chandran wrote: So using a `def` file is a must I think. no it is not. you just need to mark things export and make sure names match (including module name) Thanks for the reply.

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

2022-07-01 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 1 July 2022 at 22:32:24 UTC, Vinod K Chandran wrote: So using a `def` file is a must I think. no it is not. you just need to mark things export and make sure names match (including module name)

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

2022-07-01 Thread Vinod K Chandran via Digitalmars-d-learn
On Friday, 1 July 2022 at 22:22:42 UTC, mw wrote: Try follow instructions here: https://wiki.dlang.org/Win32_DLLs_in_D Thanks. So using a `def` file is a must I think. At first, I thought I can skip that.

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

2022-07-01 Thread mw via Digitalmars-d-learn
On Friday, 1 July 2022 at 21:15:50 UTC, Vinod K Chandran wrote: On Friday, 1 July 2022 at 21:02:20 UTC, mw wrote: I think the problem is the linker looking for dime.testFunc, while your lib function is dimedll.testFunc Thanks for the reply. What about this `mixin SimpleDllMain;` I suspect

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

2022-07-01 Thread Vinod K Chandran via Digitalmars-d-learn
On Friday, 1 July 2022 at 21:02:20 UTC, mw wrote: I think the problem is the linker looking for dime.testFunc, while your lib function is dimedll.testFunc Thanks for the reply. What about this `mixin SimpleDllMain;` I suspect this.

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

2022-07-01 Thread mw via Digitalmars-d-learn
On Friday, 1 July 2022 at 19:11:16 UTC, Vinod KC wrote: Hi all, I have created a dll file with this code. ```d module dimedll; export void testFunc() { writeln("This is from dll"); } ``` void main() { log("Lets build our own ime"); testFunc(); } ``` ```

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

2022-07-01 Thread Vinod K Chandran via Digitalmars-d-learn
On Friday, 1 July 2022 at 20:08:45 UTC, ryuukk_ wrote: I think it is `extern(D) void testFunc();`? Thanks for the reply. But the result is same linker error.

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

2022-07-01 Thread ryuukk_ via Digitalmars-d-learn
I think it is `extern(D) void testFunc();`?

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

2022-07-01 Thread Vinod KC via Digitalmars-d-learn
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