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

WhatMeWorry kheaser at gmail.com
Sun Oct 18 21:44:10 UTC 2020


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.




More information about the Digitalmars-d-learn mailing list