I recently developed a project in C which makes use of the function clock_gettime() in linux. The linking for this on my Ubuntu desktop is achieved using the linker flag:
gcc -lrt foo.c
I was excited to read that I could cross-compile my project for the Android in the post below.
http://benno.id.au/blog/2007/11/13/android-native-apps
I’ve tried this on trivial projects though using the command:
arm-linux-gnueabi-gcc -static foo.c -o foo
Rather than the command:
arm-none-linux-gnueabi-gcc -static foo.c -o foo
referred to in the link, and they do indeed compile and link fine, but when I try with my project requiring clock_gettime() and the linking:
-ltr
It fails with:
undefined reference to `clock_gettime'
I’ve read that library specified by -lrt doesn’t exist for the Android, and I’ve found posts other places claiming that folks are using clock_gettime() on Android projects, but I haven’t been able to find the right library to link to for this. Can anyone tell me what I need to link to for the ARM to make this work?
Or make any other suggestions as to alternatives that will work on the Android.
I am very much interested in leveraging my existing makefiles from my Desktop linux projects to what extent I can, but reconfiguring them to work with the cross-compile tool chain if possible, so any suggestions which would allow for that would be very greatly appreciated.
Android’s “bionic” C library has a wrapper for the
clock_gettime()syscall. If you build using the Android NDK you’ll get that automatically. Otherwise you need to add a bionic library to your toolchain somehow.Alternatively, you could call the syscall directly via assembly (from memory, the first argument goes in R0, the second in R1, you put the syscall number in R7, issue “SWI $0” and find the result code in R0).
Alternatively: why are you bothering with clock_gettime? Is there any reason you can’t simply use gettimeofday()?