Unable to get Phobos working on Ubuntu x64 (Oneiric)

Jonathan M Davis jmdavisProg at gmx.com
Sun Sep 18 03:39:35 PDT 2011


On Friday, September 16, 2011 23:15:16 Kiith-Sa wrote:
> Jonathan M Davis wrote:
> > On Friday, September 16, 2011 12:47 Kiith-Sa wrote:
> >> I've just installed a new system - Ubuntu 11.10 beta x64 and can't get
> >> dmd/phobos 2.055 to work.
> >> 
> >> When I try to compile file hello.d with the following content:
> >> 
> >> import std.stdio;
> >> 
> >> void main()
> >> {
> >> writeln("Hello World!");
> >> }
> >> 
> >> 
> >> I get this error:
> >> 
> >> /usr/lib/gcc/x86_64-linux-
> >> gnu/4.6.1/../../../../lib/libphobos2.a(datetime_48b_1ec.o): In
> >> function
> >> `_D3std8datetime5Clock11currStdTimeFNdNeZl':
> >> std/datetime.d:(.text._D3std8datetime5Clock11currStdTimeFNdNeZl+0x1d):
> >> undefined reference to `clock_gettime'
> >> /usr/lib/gcc/x86_64-linux-
> >> gnu/4.6.1/../../../../lib/libphobos2.a(time_c0_4d1.o): In function
> >> `_D4core4time12TickDuration12_staticCtor7OFNeZv':
> 
> >> src/core/time.d:
> (.text._D4core4time12TickDuration12_staticCtor7OFNeZv+0x1f)
> 
> >> : undefined reference to `clock_getres'
> >> 
> >> /usr/lib/gcc/x86_64-linux-
> >> gnu/4.6.1/../../../../lib/libphobos2.a(time_c0_4d1.o): In function
> 
> `_D4core4time12TickDuration14currSystemTickFNdNeZS4core4time12TickDuration'
> 
> >> : src/core/time.d:
> (.text._D4core4time12TickDuration14currSystemTickFNdNeZS4core4time12TickDur
> 
> >> ation+0x1f): undefined reference to `clock_gettime'
> >> collect2: ld returned 1 exit status
> >> --- errorlevel 1
> >> 
> >> 
> >> Nothing else using Phobos compiles either.
> >> 
> >> I've seen previous related threads. Tried -L-lrt, didn't work.
> >> I tried the .deb package for Ubuntu, the binaries shipped
> >> in the source archive, as well as compiling Phobos myself (removing
> >> DMD/Phobos every time to make sure no files persisted), but nothing
> >> helped.
> >> 
> >> 
> >> Has anyone encountered this problem? Did anyone get it to work on
> >> Ubuntu
> >> (especially 11.10)?
> > 
> > It's clearly an issue where it can't find librt, since clock_gettime is
> > in librt. As long as you didn't mess with dmd.conf, -L-lrt should
> > already be given to the compiler, but regardless, if you passed it
> > yourself, it should work.
> > 
> > Are you using a 64-bit binary of dmd or a 32-bit binary? If you're using
> > a 32- bit binary (or building for 32-bit with a 64-bit binary), then
> > you're going to need the 32-bit libraries for glibc, pthreads, and
> > librt (I don't know what packages those are on Ubuntu, but if you have
> > the 32-bit libraries installed at all, odds are that those ones are
> > there).
> > 
> > - Jonathan M Davis
> 
> I'm using the 64bit binary. DMD uses the following to link (from verbose
> output):
> 
> gcc hello.o -o hello -m64 -Xlinker -L/usr/lib64 -Xlinker -L/usr/lib32 -
> Xlinker --no-warn-search-mismatch -Xlinker --export-dynamic -lrt -lphobos2 -
> lpthread -lm
> 
> librt.so is present in /usr/lib/x86_64-linux-gnu , also copied it to
> /usr/lib . Still the same error.

librt.a is needed as well, so maybe that's the problem. /usr/lib/x86_64-linux-
gnu strikes me as a weird place to put it regardless. You should probably 
check whether it's in your linker's path. If so, it should be listed in 
/etc/ld.so.conf.

If librt.a is clearly in the linker's path, then I'd try just downloading the 
dmd zip file, unzipping it, adding /path/to/unzipped/dmd2/linux/bin/ to your 
path before wherever the installed dmd is (or adding it to your wherever in 
your path and uninstall the installed dmd) and seeing whether that works. I 
would hope that that wouldn't be necessary though.

But clearly, the linker is not finding librt, and that's what needs to be fixed. 
I'm not an Ubuntu user though, so I don't know exactly what Ubuntu does 
differently or how dmd is installed with the .deb file. Personally, I've always 
use the zip file without trying to install dmd with the package manager or move 
any of its associated tools or libraries into /usr/ or /usr/local.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list