dmd link mystery on linux

Mike Wey mike-wey at example.com
Sun May 20 06:53:20 PDT 2012


On 05/20/2012 01:58 AM, John Belmonte wrote:
> I'm having a problem where the link command line generated by dmd is
> picking up the globally-installed version of the phobos library instead
> of my local one. I'm using a dmd.conf pointing at my local phobos build
> so this shouldn't be happening. From output of "dmd rdmd.d -v":
>
> gcc rdmd.o -o rdmd -m64 -Xlinker
> -L/home/john/dev/d/phobos/generated/linux/release/64 -lphobos2 -lpthread
> -lm -lrt
>
> which looks right to me (referenced dir contains libphobos2.a). I know
> this is picking up the wrong phobos2 because the globally-installed
> version is missing some required symbols. If I move the global .a out of
> the way my local lib is picked up and the link and subsequent run are fine.
>
> More strangely, if I remove -Xlinker from that link line my local lib is
> again picked up. From my understanding, omitting -Xlinker causes gcc to
> interpret the -L option natively. Does anyone know why this would make a
> difference, or can anyone point out what I'm missing?
>
> Also, I'm wondering if anyone else would find it useful for the
> update.sh tool to automatically generate a dmd.conf which points to the
> local druntime and phobos.
>

On my system it looks like the order of the commands passed on to ld 
differ depending on if -Xlinker is used.
gcc passes some default paths to the linker like: -L/lib/ and 
-L/usr/lib/, now commands passed on to the linker with -Xlinker are 
added after these paths, while if you don't use -Xlinker the path is 
passed before the default paths.

So if your global phobos lib is installed in /lib or /usr/lib it will be 
picked up by the linker if it searches those directories before the one 
that contains the local one. The search order for ld depends on the 
order in which they appear on the commandline.

-- 
Mike Wey


More information about the Digitalmars-d mailing list