Re: D function in a .d file calling printf refuses to link.

2020-10-19 Thread Siemargl via Digitalmars-d-learn

On Sunday, 18 October 2020 at 21:44:10 UTC, WhatMeWorry wrote:

module mydll;

extern (C):
import core.stdc.stdio : printf;
export
{
int addSeven(int a, int b)
{
//printf("Hello from within my DLL");
return a+b+7;
}
}

The above D code file compiles and links, no problems with
C:\D\dmd2\samples\d\mydll>dmd -v -m64 mydll.d -L/DLL -L/NOENTRY

But as soon as I uncomment the printf, all hell breaks loose 
with


legacy_stdio_definitions.lib(legacy_stdio_definitions.obj) : 
error LNK2019: unresolved external symbol __acrt_iob_func 
referenced in function _vwprintf_l
legacy_stdio_definitions.lib(legacy_stdio_definitions.obj) : 
error LNK2019: unresolved external symbol 
__stdio_common_vfwprintf referenced in function _vfwprintf_l
legacy_stdio_definitions.lib(legacy_stdio_definitions.obj) : 
error LNK2019: unresolved external symbol 
__stdio_common_vfwprintf_s referenced in function _vfwprintf_s_l

   o  o  o


Walter Bright even wrote a three line module at
https://github.com/dlang/dmd/blob/master/samples/mydll/mydll.d
which uses the printf.


It appears as you use recent Microsoft Linker and toolset. Which 
requires adding legacy_stdio_definitions.lib in linking list.


Also i tested this example with DMD 2.092.1 - completed 
succesfully. It uses mingw toolset and lld-link. (I have no VS 
installed)


D function in a .d file calling printf refuses to link.

2020-10-18 Thread WhatMeWorry via Digitalmars-d-learn

module mydll;

extern (C):
import core.stdc.stdio : printf;
export
{
int addSeven(int a, int b)
{
//printf("Hello from within my DLL");
return a+b+7;
}
}

The above D code file compiles and links, no problems with
C:\D\dmd2\samples\d\mydll>dmd -v -m64 mydll.d -L/DLL -L/NOENTRY

But as soon as I uncomment the printf, all hell breaks loose with

legacy_stdio_definitions.lib(legacy_stdio_definitions.obj) : 
error LNK2019: unresolved external symbol __acrt_iob_func 
referenced in function _vwprintf_l
legacy_stdio_definitions.lib(legacy_stdio_definitions.obj) : 
error LNK2019: unresolved external symbol 
__stdio_common_vfwprintf referenced in function _vfwprintf_l
legacy_stdio_definitions.lib(legacy_stdio_definitions.obj) : 
error LNK2019: unresolved external symbol 
__stdio_common_vfwprintf_s referenced in function _vfwprintf_s_l

   o  o  o


Walter Bright even wrote a three line module at
https://github.com/dlang/dmd/blob/master/samples/mydll/mydll.d
which uses the printf.