December 09, 2017
https://issues.dlang.org/show_bug.cgi?id=18046

Timothee Cour <timothee.cour2@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timothee.cour2@gmail.com

--- Comment #1 from Timothee Cour <timothee.cour2@gmail.com> ---
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)

--
December 09, 2017
https://issues.dlang.org/show_bug.cgi?id=18046

David Nadlinger <code@klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@klickverbot.at

--- Comment #2 from David Nadlinger <code@klickverbot.at> ---
(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.

--