When I try compiling a simple Windows DLL using DMD it works fine, but when I try doing it in BetterC mode I get "Error 42: Symbol Undefined __acrtused_dll". I guess the compiler generates calls to this function while compiling a DLL and this function is not defined in Cruntime, but rather defined in Druntime or Phobos. I think it should be possible to compile DLLs in BetterC mode, so this is a bug.
(In reply to kinke from comment #1)
> This seems to be specific to the DigitalMars C runtime, see
> https://digitalmars.com/ctg/acrtused.html. You may have more luck with
> -m32mscoff or -m64.
It doesn't compile with -m32mscoff or -m64 either:
> dmd -of=dll.dll -betterC -m32mscoff dll.d
lld-link.exe: error: subsystem must be defined
Error: linker exited with status 1
> dmd -of=dll.dll -betterC -m64 dll.d
lld-link.exe: error: subsystem must be defined
Error: linker exited with status 1
Comment #3 by kinke — 2019-04-02T18:21:58Z
This (linker) error can be gotten rid of with -L=/SUBSYSTEM:CONSOLE.
Comment #4 by relmail — 2019-04-03T12:10:18Z
(In reply to kinke from comment #3)
> This (linker) error can be gotten rid of with -L=/SUBSYSTEM:CONSOLE.
I think the better thing to do is /DLL, but still I got these errors:
> dmd -of=dll.dll -betterC -L=/DLL -m32mscoff dll.d
lld-link.exe: error: <root>: undefined symbol: __DllMainCRTStartup@12
lld-link.exe: error: undefined symbol: _MessageBoxA@16
>>> referenced by dll.obj:(_Test@0)
Error: linker exited with status 1
If I do /SUBSYSTEM:CONSOLE I get:
> dmd -of=dll.dll -betterC -L=/SUBSYSTEM:CONSOLE -m32mscoff dll.d
lld-link.exe: error: entry point must be defined
Error: linker exited with status 1
If I add /ENTRY:DllMain to that I get:
> dmd -of=dll.dll -betterC -L=/SUBSYSTEM:CONSOLE -L=/ENTRY:DllMain -m32mscoff dll.d
lld-link.exe: error: undefined symbol: _MessageBoxA@16
>>> referenced by dll.obj:(_Test@0)
Error: linker exited with status 1
Comment #5 by bugzilla — 2023-01-15T06:29:13Z
__acrtused_dll is defined in snn.lib, which should be linked in for win32 DLL builds.
Comment #6 by robert.schadek — 2024-12-13T19:02:47Z