-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hello,
I write a simple test example about time function.but when I use the "time()" function,the code can not be compiled correctly. I just have include the <time.h>,any question?
Not quite correct. Including <time.h> only pulls the _declaration_ of the time() function into your program. In order to actually use it, you also need to have a _definition_ of this function available.
As your local C text book will tell you, there are two ways of getting the definition of a function: 1) implement it in your code 2) link your program with a library providing this function
the error I put following: l4@192:~/tudos/l4/pkg/test_fifo/examples/client$ make PWD=/home/l4/tudos/build/pkg/test_fifo/examples/client/OBJ-x86_586-l4v2 make -C /home/l4/tudos/build/pkg/test_fifo/examples/client/OBJ-x86_586-l4v2 -f Makefile make[1]: Entering directory `/home/l4/tudos/build/pkg/test_fifo/examples/client/OBJ-x86_586-l4v2' ... Compiling main.o LD_PRELOAD=/home/l4/tudos/build/tool/gendep/libgendep.so GENDEP_TARGET=main.o GENDEP_BINARY=cc1 gcc -m32 -c -DUSE_UCLIBC=y -DRAM_BASE=0x0 -DSYSTEM_x86_586_l4v2 -DARCH_x86 -DCPUTYPE_586 -DL4API_l4v2 -DCONFIG_L4_CALL_SYSCALLS -DCONFIG_L4_ABS_SYSCALLS -I/home/l4/tudos/build/pkg/test_fifo/idl/OBJ-x86-l4v2 -I/home/l4/tudos/build/include/x86/l4v2 -I/home/l4/tudos/build/include/l4v2 -I/home/l4/tudos/build/include/x86 -I/home/l4/tudos/build/include -I/home/l4/tudos/l4/../dice/include -I/home/drops/include/x86/l4v2 -I/home/drops/include/l4v2 -I/home/drops/include/x86 -I/home/drops/include -nostdinc -I/home/l4/tudos/build/include/x86/uclibc -I/home/l4/tudos/build/include/uclibc -I/home/l4/tudos/build/include/uclibc++ -I/home/drops/include/x86/uclibc -I/home/drops/include/uclibc -I/home/drops/include/uclibc++ -I/usr/lib/gcc/i486-linux-gnu/4.2.4/include -I/usr/lib/gcc/i486-linux-gnu/4.2.4/include-fixed -gstabs+ -g -O2 -fno-strict-aliasing -march=i586 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -fno-common -fno-stack-protector /home/l4/tudos/l4/pkg/test_fifo/examples/client/main.c -o main.o ==> Linking test_fifo-client LD_PRELOAD=/home/l4/tudos/build/tool/gendep/libgendep.so GENDEP_TARGET=test_fifo-client GENDEP_BINARY=ld GENDEP_BINARY_ALT1=ld ld -m elf_i386 -o test_fifo-client /home/l4/tudos/build/lib/x86_586/crt0.o main.o test-client.o -Ttext=0x1100000 --hash-style=sysv -L/home/l4/tudos/build/lib/x86_586/l4v2 -L/home/l4/tudos/build/lib/x86_586 -L/home/l4/tudos/build/lib -L/home/drops/lib/x86_586/l4v2 -L/home/drops/lib/x86_586 -L/home/drops/lib -T/home/l4/tudos/build/lib/x86_586/main_stat.ld -static -lgeneric_ts -ll4env -ll4rm -ldm_generic -ldm_mem -lthread -lsemaphore -llogserver_capsule -lnames -ll4util_root -ll4util -lsigma0 -lroot -ll4env -ll4env_err -ll4rm -ldm_generic -ldm_mem -lthread -lslab -ll4sys -nostdlib -luc_c -luclibc_support -u mmap_anon -lc_be_simple_mem -lc_be_mmap -lc_be_mmap_util -lc_be_l4env_start_stop -lc_be_minimal_log_io -luc_be_simple_sleep -ll4env -llogserver_capsule -ll4rm -ldm_generic -ldm_mem -lthread -lgeneric_ts -luc_c /usr/lib/gcc/i486-linux-gnu/4.2.4/libgcc.a -luc_c -ll4sys -Ttext=0x1100000 --warn-common -gc-sections main.o: In function `main': /home/l4/tudos/l4/pkg/test_fifo/examples/client/main.c:36: undefined reference to `time' /home/l4/tudos/l4/pkg/test_fifo/examples/client/main.c:40: undefined reference to `time' /home/l4/tudos/l4/pkg/test_fifo/examples/client/main.c:36: undefined reference to `time'
This is what the linker is telling you here: I cannot find a definition of time(), but i desparately need one.
[..]
I have search the same error in l4-hackers ,someone suggest use rtc server,I think it's a good idea.but I have found that the time() function in time.h,why the error will happen? The reason I just include time.h?
Indeed, the time() function is provided by libc_be_time, which comes as part of the rtc package. So what you need to do is add
LIBS += -lc_be_time
to your Makefile.
Cheers, Bjoern