This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: building something with nanotime
- From: Brian Dessent <brian at dessent dot net>
- To: Jim Stapleton <stapleton dot 41 at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 31 Aug 2007 12:27:42 -0700
- Subject: Re: building something with nanotime
- References: <80f4f2b20708311155p4abc608as49f13d179a885ee@mail.gmail.com>
- Reply-to: gcc-help at gcc dot gnu dot org
Jim Stapleton wrote:
> FreeBSD
> ========================================
> [sjss@elrond ~/dev/numbench]$ gcc numbench.c
> /var/tmp//ccnZ4l7C.o(.text+0x155c): In function `loop_calibrate':
> : undefined reference to `nanotime'
> /var/tmp//ccnZ4l7C.o(.text+0x15b6): In function `loop_calibrate':
> : undefined reference to `nanotime'
> /var/tmp//ccnZ4l7C.o(.text+0x15ec): In function `iterbenchI':
> : undefined reference to `nanotime'
> /var/tmp//ccnZ4l7C.o(.text+0x165d): In function `iterbenchI':
> : undefined reference to `nanotime'
> /var/tmp//ccnZ4l7C.o(.text+0x1694): In function `iterbenchF':
> : undefined reference to `nanotime'
> /var/tmp//ccnZ4l7C.o(.text+0x1705): more undefined references to
> `nanotime' follow
> ========================================
On FreeBSD this is a kernel mode interface, not available to userspace.
That is why the manpage is in section 9. So you can't call this
function from a normal program.
> Cygwin:
> ========================================
> $ gcc numbench.c -lc -lm
> /cygdrive/c/DOCUME~1/STAPLE~1/LOCALS~1/Temp/ccSqoE54.o:numbench.c:(.text+0x2b4):
> undefined reference to `_srandomdev'
> /cygdrive/c/DOCUME~1/STAPLE~1/LOCALS~1/Temp/ccSqoE54.o:numbench.c:(.text+0x13ef):
> undefined reference to `_nanotime'
> /cygdrive/c/DOCUME~1/STAPLE~1/LOCALS~1/Temp/ccSqoE54.o:numbench.c:(.text+0x1445):
> undefined reference to `_nanotime'
> /cygdrive/c/DOCUME~1/STAPLE~1/LOCALS~1/Temp/ccSqoE54.o:numbench.c:(.text+0x1478):
> undefined reference to `_nanotime'
> /cygdrive/c/DOCUME~1/STAPLE~1/LOCALS~1/Temp/ccSqoE54.o:numbench.c:(.text+0x14e5):
> undefined reference to `_nanotime'
> /cygdrive/c/DOCUME~1/STAPLE~1/LOCALS~1/Temp/ccSqoE54.o:numbench.c:(.text+0x1518):
> undefined reference to `_nanotime'
> /cygdrive/c/DOCUME~1/STAPLE~1/LOCALS~1/Temp/ccSqoE54.o:numbench.c:(.text+0x1585):
> more undefined references to `_nanotime' follow
> collect2: ld returned 1 exit status
> ========================================
Cygwin does not provide the nanotime function.
> I tried adding a few libraries that might be useful: -lc -lm -lmd
> -lpthread, but with no luck. I figured I'd try to find what library it
> is in, but couldn't (strings /lib/* | grep nano; string /usr/lib/* |
> grep nano). I could only find nanosleep, and a few other non-nanotime
> references.
The problem is that you're expecting to be able to use a nonstandard
function where it does not exist. I think you need to switch APIs if
you want to build your code on these platforms. gettimeofday(2) should
give you microsecond resolution and is POSIX standard.
Brian