Link-time error when used _strdate() and _strtime()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Akino877
    New Member
    • Nov 2007
    • 37

    Link-time error when used _strdate() and _strtime()

    Hi,

    I am trying to compile the following program :

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

    int main( )
    {
    char dateStr [9];
    char timeStr [9];

    _strdate( dateStr);
    printf( "The current date is %s \n", dateStr);
    _strtime( timeStr );
    printf( "The current time is %s \n", timeStr);
    }

    and get the following compile/link time error message :

    $ gcc date.c
    /tmp/ccyJ9mFr.o: In function `main':
    date.c:(.text+0 x23): undefined reference to `_strdate'
    date.c:(.text+0 x41): undefined reference to `_strtime'
    collect2: ld returned 1 exit status
    $

    It appeared that the program compiled OK. But the linker could not find
    _strdate and _strtime.

    Does anyone how to fix this problem?

    Thank you for your help.

    Akino.
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #2
    Aside: please use CODE tags when posting code. We programmers need to see properly formatted code, so if you want the most help for your questions, do take the time to add those tags. It doesn't take long, but lots more people will help you out.

    You may be surprised to learn that _strdate and _strtime are not part of standard C. They are Microsoft extensions to time.h, which do not exist in other compilers. Hence, gcc can't compile the code, because _strdate and _strtime do not exist.

    Comment

    Working...