Thread overview
Name mangling problem with tiny Windows 10 load-time DLL example
Feb 28, 2021
WhatMeWorry
Feb 28, 2021
Kagamin
Feb 28, 2021
Siemargl
Feb 28, 2021
WhatMeWorry
Mar 01, 2021
Siemargl
February 28, 2021
It seems pretty obvious the problem is with name mangling. But how to fix it?

------------------------------------------------------------------
module file;
extern(D) export
{
    int addOne(int i) { return (i + 1); }
}
------------------------------------------------------------------
module patron;
import file;	
void main()
{
    import std.stdio;
    int n = 1;
    writeln("mangled name of addOne is ", addOne.mangleof);
    numb = addOne(numb);
}
------------------------------------------------------------------
ldc2 -m64 -c file.d
ldc2 -m64 -c patron.d

ldc2 -m64 -shared file.obj -ofloadTime.dll
   Creating library loadTime.lib and object loadTime.exp

Both dumpbin /exports loadTime.lib and dumpbin /exports loadTime.dll
shows:  _D4file6addOneFiZi				
				
ldc2 patron.obj loadTime.lib

patron.exe
mangled name of addOne is _D6patron6addOneFiZi

// and library function is never called. Does not abend though???

-------------------------------------------------------------------

So the library function is named _D4file6addOneFiZi while the user wants to call _D6patron6addOneFiZi

So which name is "correct" and how do I get them to agree with each other?


		
February 28, 2021
mangleof should give _D4file6addOneFiZi, not _D6patron6addOneFiZi
February 28, 2021
On Sunday, 28 February 2021 at 18:29:11 UTC, WhatMeWorry wrote:
> It seems pretty obvious the problem is with name mangling. But how to fix it?
>
fixing
>    int numb = 1;

and your example work correct

ldc 1.24 / win10

P.S.I'm not recommend using such keywords as 'file', may cross with other modules.
February 28, 2021
On Sunday, 28 February 2021 at 22:10:21 UTC, Siemargl wrote:
> On Sunday, 28 February 2021 at 18:29:11 UTC, WhatMeWorry wrote:
>> It seems pretty obvious the problem is with name mangling. But how to fix it?
>>
> fixing
>>    int numb = 1;
>
> and your example work correct
>
> ldc 1.24 / win10
>
> P.S.I'm not recommend using such keywords as 'file', may cross with other modules.

I double checked my posting and of course works it now works!?!?  I've been having trouble where it works and then it doesn't. I've been using examples with file.d, file1.d, file2.d, etc.  I also came across the note that Windows file system is not case sensitive. Or is that case in-sensitive?

This worked fine for Linux (Ubuntu) so you might be on to something.
March 01, 2021
On Sunday, 28 February 2021 at 23:00:56 UTC, WhatMeWorry wrote:
> On Sunday, 28 February 2021 at 22:10:21 UTC, Siemargl wrote:
>> On Sunday, 28 February 2021 at 18:29:11 UTC, WhatMeWorry wrote:
>>> It seems pretty obvious the problem is with name mangling. But how to fix it?
>>>
>> fixing
>>>    int numb = 1;
>>
>> and your example work correct
>>
>> ldc 1.24 / win10
>>
>> P.S.I'm not recommend using such keywords as 'file', may cross with other modules.
>
> I double checked my posting and of course works it now works!?!?  I've been having trouble where it works and then it doesn't. I've been using examples with file.d, file1.d, file2.d, etc.  I also came across the note that Windows file system is not case sensitive. Or is that case in-sensitive?
>
> This worked fine for Linux (Ubuntu) so you might be on to something.

Win10. Just try delete all obj, dll, lib and do full recompile from scratch.

module patron;
import file;	
void main()
{
    import std.stdio;
    int numb = 1;
    writeln("mangled name of addOne is ", addOne.mangleof);
    numb = addOne(numb);
    writeln(numb);
}

---------
E:\VSProjects\testjunk\D_load_dll>patron.exe                                                                                                                                                                       mangled name of addOne is _D4file6addOneFiZi                                                                                                                                                                       2