July 03, 2022

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 be defined in the executable? dimedll.d isn't compiled into the executable.

>

A static linked function should generate a very small lib-file and yours look too big to me.

The code is using Phobos std.stdio.writeln templates, so the ~20 KB for both exe and DLL are to be expected and IMO absolutely acceptable.

>

I don't know about LDC but with DMD I struggle with static linked DLLs because the library generated does not link to the DLL. To get right results, I need to pass the linker flag --L=/IMPLIB (or -L=/DLL for 64bit) to generate a lib-file that is really linked to the DLL later.

DMD's DLL support is waaay behind LDC's, especially once stuff gets more interesting than trivial examples.

July 03, 2022

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 templates, so the ~20 KB for both exe and DLL are to be expected and IMO absolutely acceptable.

DMD's DLL support is waaay behind LDC's, especially once stuff gets more interesting than trivial examples.

Yeah, I tried LDC and there are differences:

The library file generated by LDC contains the link to the DLL.
The library file generated by DMD is missing that link.

So linking the DMD library would embed the symbol from the library - that was my confusion with your example.

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) :\

Also the -H switch doesn't work correctly. Without supplying -L/DLL flag too, I get link error:

1561: entry point must be defined
July 04, 2022

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) :\

dmd -shared / dmd -H -shared seems to work too (library contains link to DLL). Don't know why I had in mind that it would fail - maybe it did in the past.

However both DMD and LDC produces questionable header files for this task.

July 07, 2022

On Sunday, 3 July 2022 at 09:43:20 UTC, frame wrote:

>

app.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 in the DLL and run the executable wihtout re-compiling (the library file should be round ~2kB).

PS: ddemangle just waits for your input. You copy in the mangled symbol like __D7dimedll12__ModuleInfoZ and press enter ;-)

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 and compiling in an additional copy of each fuction.

July 08, 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.

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.

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. Next, change dimedll.d to the following:

module dimedll;
export void testFunc()
{
    import std.stdio;
    writeln("Lets build our own ime.");
}

and dime.d to the following:

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.

July 08, 2022

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 and compiling in an additional copy of each fuction.

IMHO this is the expected behaviour since the compiler comes before the linker and pragma(lib) is a linker directive, so if dimedll.di is not present it looks for dimedll.d instead and just compiles the code.

The link to DLL is only present in the actual lib-file and only used by the linker.

The pitfall with DMD is that the automatic generated di-file is not usable as it contains a mixin that is meant for the DLL but not the application that links it, resulting in _ModuleInfoZ error while trying.

1 2 3
Next ›   Last »