Bug 18046 – dmd -unittest doesn't work when linking against a shared library

Status
NEW
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2017-12-07T22:16:21Z
Last change time
2024-12-13T18:55:18Z
Assigned to
No Owner
Creator
Timothee Cour
Moved to GitHub: dmd#19341 →

Comments

Comment #0 by timothee.cour2 — 2017-12-07T22:16:21Z
on OSX, dmd -unittest doesn't work when linking against a shared library (but works when linking against a static library): even though main2.d was compiled with -unittest, main2's unittest isn't called. dmd --version DMD64 D Compiler v2.077.0 dmd -of=build//libfoo.dylib -shared -unittest foo.d dmd -unittest -ofbuild/./main -L-lfoo -L-Lbuild/ main2.d foo.d build/./main u:foo rm build//libfoo.dylib dmd -of=build//libfoo.a -lib -unittest foo.d dmd -unittest -ofbuild/./main -L-lfoo -L-Lbuild/ main2.d foo.d build/./main u:main2 u:foo ##### ./main2.d: module main2; import std.stdio; import foo; void main(){} unittest{ import std.stdio; writeln("u:main2"); } ./foo.d: module foo; void fun(){} unittest{ import std.stdio; writeln("u:foo"); }
Comment #1 by timothee.cour2 — 2017-12-09T00:30:21Z
same with ldmd2: ldmd2 -of=build//libfoo.dylib -shared -unittest foo.d ldmd2 -unittest -ofbuild/./main -L-lfoo -L-Lbuild/ main2.d foo.d build/./main ldmd2 --version LDC - the LLVM D compiler (1.6.0): based on DMD v2.076.1 and LLVM 5.0.0 built with LDC - the LLVM D compiler (0.17.5)
Comment #2 by code — 2017-12-09T01:51:51Z
(In reply to Timothee Cour from comment #1) > same with ldmd2: > > ldmd2 -of=build//libfoo.dylib -shared -unittest foo.d > ldmd2 -unittest -ofbuild/./main -L-lfoo -L-Lbuild/ main2.d foo.d > build/./main > > ldmd2 --version > LDC - the LLVM D compiler (1.6.0): > based on DMD v2.076.1 and LLVM 5.0.0 > built with LDC - the LLVM D compiler (0.17.5) This only occurs when not linking against the shared runtime (druntime/Phobos), which is a prerequisite for using shared libraries in user code. Note also that you are compiling foo.d twice, which will be (correctly) rejected by LDC on startup. (The module collision check has been removed in druntime master, so you won't be protected against this mistake in the future, but it's still not what you want.) After fixing that, LDC gives u:foo u:main2 as expected.
Comment #3 by robert.schadek — 2024-12-13T18:55:18Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19341 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB