Hi,
I'm new to D and trying my hands on a few simple things. Being able to build a Windows DLL with betterC enabled is of particular interest to me, as I'd need it for a project that I'd like to do in D.
I'm trying to follow some examples, such as this and this, and they compile without -betterC
, but fail with link errors when using the switch.
example DLL, or see 2nd link for one without the mixin
//WindowsApp1.d
module WindowsApp1;
import core.sys.windows.windows;
import core.sys.windows.dll;
export extern (C) void main()
{
import core.stdc.stdio : printf;
printf("Hello betterC\n");
}
mixin SimpleDllMain;
then
dmd -m64 -shared -betterC WindowsApp1.d
yields error:
error LNK2019: unresolved external symbol _D4core3sys7windows3dll18dll_process_attachFPvbZb referenced in function DllMain
error LNK2019: unresolved external symbol _D4core3sys7windows3dll18dll_process_detachFPvbZv referenced in function DllMain
error LNK2019: unresolved external symbol _D4core3sys7windows3dll17dll_thread_attachFbbZb referenced in function DllMain
error LNK2019: unresolved external symbol _D4core3sys7windows3dll17dll_thread_detachFbbZb referenced in function DllMain
I'm not a complete beginner to programming, so I'm guessing the linker is missing a library, but as I'm not familiar with D yet, and these are fairly basic examples that I expected to run without a hitch, I'm a bit confused as to what I should be doing. Shouldn't the system modules provide the link targets themselves? Should I add a parameter to include a windows system library?
BtW, I've tried compiling from the command line and from Visual Studio using the visuald extension - I'm assuming the extension makes sure the environment variables are set correctly. When using dmd from the command line, I also tried invoking dmd2vars64.bat
and vcvars64.bat
before running dmd.exe to ensure the variables are set. In any case, the build process is successful without betterC
, so I'm assuming the path/variables are set correctly.