Bug 1156 – Installed libraries need to be passed in different order
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
Other
OS
Linux
Creation time
2007-04-17T11:20:00Z
Last change time
2014-02-16T15:22:14Z
Assigned to
bugzilla
Creator
larsivar
Comments
Comment #0 by larsivar — 2007-04-17T11:20:12Z
DMD don't understand how to order libraries on Linux. In short, ld (and gcc which DMD use for linking) needs that libraries are passed in dependency order. That is, if library A depends on library B, then the linker needs that A is passed before B. Since all D libraries depends on libphobos, they must be passed before phobos on the command line. This works as it should if you pass the library with full name and path, for instance
dmd mysource.d libmylib.a
This also works if libmylib.a is put in dmd.conf/DFLAGS with the full path.
However, if a library is installed in for instance /usr/lib or /usr/local/lib, gcc will find it if it is given the command -lmylib. Passing this via DMD, using the -L switch (like -L-lmylib ) will not work, because these are added at the end of the gcc commandline, that is after libphobos which it depends on.
Thus DMD should always pass additional arguments to the linker before libphobos on the argument line. An additional thing one could do, was to check if -L is followed by -l, in which case -Xlinker isn't needed.