What does this option to ld mean?
-lrt
I know to some degree it means that ld is looking for the library with real-time extensions, but after searching extensively, I couldn't find an exact definition (or which library) this is referring to.
With Bionic (android) libc, the android NDK docs detail that this (along with pthreads) has been integrated.
I ask because it seems to be implicit (ie when I invoke the compiler, a custom-compiled gdc, directly, I get a message saying that ld cannot find -lrt)
EDIT
From the Bionic Overview
Bionic's C library comes with its own pthread implementation bundled in. This is different from other historical C libraries which:
- place it in an external library (-lpthread) - play linker tricks with weak symbols at dynamic link time
The support for real-time features (a.k.a. -lrt) is also bundled in the C library.
The problem is that collect2 is passing the option -lrt (and also -lpthreads) to ld.
dan@devbox:~/projects/gdc_test/jni/src$ $DC gdc_test.d -v -mthumb
Using built-in specs.
Target: arm-linux-androideabi
Configured with: /arm/ndk-git/src/build/../gcc/gcc-4.4.3/configure --prefix=/arm/ndk-git/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86 --target=arm-linux-androideabi --host=x86_64-linux-gnu --build=x86_64-linux-gnu --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --with-gmp=/arm/ndk-git/build_run/temp-install --with-mpfr=/arm/ndk-git/build_run/temp-install --disable-libssp --enable-threads --disable-nls --disable-libmudflap --disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions --disable-shared --disable-tls --enable-languages=c,d,c++ --enable-lto --with-float=soft --with-fpu=vfp --with-arch=armv5te --enable-target-optspace --enable-shared--prefix=/arm/ndk-git/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86 --enable-initfini-array --disable-nls --prefix=/arm/ndk-git/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86 --with-sysroot=/arm/ndk-git/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/sysroot --with-binutils-version=2.19 --with-mpfr-version=2.4.1 --with-gmp-version=4.2.4 --with-gcc-version=4.4.3 --with-gdb-version=6.6 --with-arch=armv5te --enable-libstdc__-v3 --disable-werrors --enable-languages=c,d,c++ --enable-shared --enable-multilib --disable-threads --program-transform-name='s,^,arm-linux-androideabi-,'
Thread model: single
gcc version 4.4.3 20100121 (gdc hg, using dmd 1.067) (GCC)
COLLECT_GCC_OPTIONS='-v' '-mthumb' '-shared-libgcc' '-pthread' '-march=armv5te' '-mfloat-abi=soft' '-mfpu=vfp'
/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../libexec/gcc/arm-linux-androideabi/4.4.3/cc1d gdc_test.d -mbionic -fpic -quiet -dumpbase gdc_test.d -mthumb -march=armv5te -mfloat-abi=soft -mfpu=vfp -auxbase gdc_test -version -imultilib thumb -iprefix /home/dan/projects/arm-linux-androideabi-4.4.3/bin/../lib/gcc/arm-linux-androideabi/4.4.3/ -isysroot /home/dan/projects/arm-linux-androideabi-4.4.3/bin/../sysroot -fmultilib-dir=thumb -o /tmp/cc2yu97y.s
GNU D (GCC) version 4.4.3 20100121 (gdc hg, using dmd 1.067) (arm-linux-androideabi)
compiled by GNU C version 4.5.2, GMP version 4.2.4, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU D (GCC) version 4.4.3 20100121 (gdc hg, using dmd 1.067) (arm-linux-androideabi)
compiled by GNU C version 4.5.2, GMP version 4.2.4, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-v' '-mthumb' '-shared-libgcc' '-pthread' '-march=armv5te' '-mfloat-abi=soft' '-mfpu=vfp'
/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/as -v -march=armv5te -mfloat-abi=soft -mfpu=vfp -meabi=5 -o /tmp/ccuFGEfj.o /tmp/cc2yu97y.s
GNU assembler version 2.19 (arm-linux-androideabi) using BFD version (GNU Binutils) 2.19
COMPILER_PATH=/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../libexec/gcc/arm-linux-androideabi/4.4.3/:/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../libexec/gcc/:/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/
LIBRARY_PATH=/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../lib/gcc/arm-linux-androideabi/4.4.3/thumb/:/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib/thumb/:/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../lib/gcc/arm-linux-androideabi/4.4.3/:/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../lib/gcc/:/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib/:/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../sysroot/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-mthumb' '-shared-libgcc' '-pthread' '-march=armv5te' '-mfloat-abi=soft' '-mfpu=vfp'
/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../libexec/gcc/arm-linux-androideabi/4.4.3/collect2 --sysroot=/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../sysroot --eh-frame-hdr -dynamic-linker /system/bin/linker -X -m armelf_linux_eabi /home/dan/projects/arm-linux-androideabi-4.4.3/bin/../sysroot/usr/lib/crtbegin_dynamic.o -L/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../lib/gcc/arm-linux-androideabi/4.4.3/thumb -L/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib/thumb -L/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../lib/gcc/arm-linux-androideabi/4.4.3 -L/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../lib/gcc -L/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib -L/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../sysroot/usr/lib /tmp/ccuFGEfj.o -lgphobos -lm -lrt -lgcc_s -lgcc -lpthread -lc -ldl -lgcc_s -lgcc /home/dan/projects/arm-linux-androideabi-4.4.3/bin/../sysroot/usr/lib/crtend_android.o
/home/dan/projects/arm-linux-androideabi-4.4.3/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: cannot find -lrt
collect2: ld returned 1 exit status
Is there a way to override this behavior?
When you see a -lsomething
, the library name is libsomething
. Doing a man librt
says the following:
NAME
librt, libposix4 - POSIX.1b Realtime Extensions library
SYNOPSIS
cc [ flag... ] file... -lrt [ library... ]
DESCRIPTION
Functions in this library provide most of the interfaces
specified by the POSIX.1b Realtime Extension. See stan-
dards(5). Specifically, this includes the interfaces defined
under the Asynchronous I/O, Message Passing, Process
Scheduling, Realtime Signals Extension, Semaphores, Shared
Memory Objects, Synchronized I/O, and Timers options. The
interfaces defined under the Memory Mapped Files, Process
Memory Locking, and Range Memory Locking options are pro-
vided in libc(3LIB)
See the man pages for the individual interfaces in section
3RT for information on required headers.
The name libposix4 is maintained for backward compatibility
and should be avoided. librt is the preferred name for this
library.