This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

uvision: time.h undefined time symbol

hi,

could someone tell me the way to work with the time.h header file? At the moment I get the error message "undefined symbol time"

#include <stdio.h>
#include <time.h>
#include "math.h"

//....

//line which generates the error message:
time_t t = time(NULL);

I'm no sure which header file is missing... Or if there's any other error... by the way I'm working with the AT91SAM9260 controller...

best regards
Stefan

  • I found the first problem - I used the Microlib.

    Without Microlib I can start the programm, but the code

    time_t t = time(NULL);
    

    cause a SWI interrupt - but I don't know why...

    Could someone give me an example how I have to use the time.h functions e.g.

    best regards
    Stefan

  • "At the moment I get the error message 'undefined symbol time'"

    An important thing (very often missunderstod) with C is that header files only tells the compiler that a symbol exists, and its data type.

    But including a header file is not the same as linking the project with any code that contains the symbols mentioned in the header file.

    "Undefined symbol" tells you that the linker failed to locate a variable, or the implementation of a function.

    time() is an important function on a normal PC. But in an embedded system, there is no "standard" real-time clock. Some hardware has means to implement a real-time clock. Some have not. Not too many toasters have a need for a display and input buttons just to let to set the clock. After all, the bread would be dry if you arm the toaster before going to bed :)

    The bad thing here, is I that can't figure out if you can replace any underlying functions if you need to use time(), or if you should replace the function with your own...

    This is my sequence for searching (in the online manuals):

    The Keil documentation "Differences from the default C library"
    http://www.keil.com/support/man/docs/armlib/armlib_bajjibhh.htm
    mentions "Microlib provides limited support for C99 functions." and "Microlib does not support operating system functions." It isn't 100% clear what this means, but is something to think about.

    So, next step is to see if we can expand:
    "ISO C features missing from microlib"
    http://www.keil.com/support/man/docs/armlib/armlib_bajdadjh.htm
    says (about missing functions):
    "Operating system interaction
    All functions that interact with an operating system are not supported by microlib. For example, abort(), exit(), atexit(), clock(), time(), system() and getenv()."

    So, from the above you must either write all support yourself, or switch from Microlib.

    Now to the "normal" lib.

    Under the header "Tailoring other C library functions", there is this comment:
    http://www.keil.com/support/man/docs/armlib/armlib_cihchbfc.htm
    "The default implementation of these functions is semihosted. That is, each function uses semihosting."

    And in this chapter you can find time() listed. Alas, no useful information about time(), other than that it is semihosted.
    http://www.keil.com/support/man/docs/armlib/armlib_cihbfbfd.htm

    I have personally never used the time() function from the RTL - only localtime() and mktime(). Some equipment don't use a RTL. Some has a 32-bit counter for the RTL, and some uses broken-down fields for year, month, day, ...

  • By the way:
    "cause a SWI interrupt - but I don't know why..."
    is because time() is semihosted.

  • Alternatively, you could say that header files tell the compiler to assume that the symbol exists (with the type stated), and generate code accordingly. Thus compilation can proceed, but the Linker needs to see the real thing.

    Another way of putting it is that, in the header file, you make a promise to the compiler that you will provide the stated symbols; it is only the Linker that calls you to fulfil your promise

  • thank you for your really good answers.

    The bad thing here, is I that can't figure out if you can replace any underlying functions if you need to use time(), or if you should replace the function with your own...

    A few things about the project.

    I'm working with the DS1337 RTC connected via I2C. At startup I have to configurate the RTC with the right time (year, day, hours, seconds and so on). I need the RTC for the ethernet stack. But it's very seldom that the fixture has access to the internet. Moreover the fixture is not always switched on.

    So I think I should also be possible to use the localtime() function.

    At the moment I'm not sure how do I get the right time?

    best regards
    Stefan

  • 1) What do you mean by "I need the RTC for the ethernet stack"? Why would your etnernet stack need to know the exact time of day or what date it is?

    2) "At the moment I'm not sure how do I get the right time?" If your unit do need absolute time, then it is up to you to figure out where/how to get the initial time into your RTC. With ethernet support, you may possibly use an SNTP implementation - a quite simple way of requesting time using UDP.

  • 1) I also want to install the protocoll snmp.

    2) SNTP - I will take a look over this protocoll. If it is possible to get a right time from another computer in the local-net then it will solve my problem...and everything would be right.

    thanks for the hint

    best regards
    Stefan