2

So, when I use the function strptime I get both a warning:

warning: implicit declaration of function 'strptime'

and an error after that:

undefined reference to 'strptime'

Yes, I've included time.h. Here is a small sample code of me using it.

#include <time.h>

void my_function()
{
    char buf* = "2016-02-05 12:45:10";
    struct tm time*;
    ...
    strptime(buf, "%F %T", &time);
    ...
}

I know time.h is working because in the same .c file, I'm using strftime, time_t, and 'struct tm from time.h without a problem. I know it's strptime, because when I comment that line of code, it compiles without any problems.

Rob Avery IV
  • 3,562
  • 10
  • 48
  • 72
  • 1
    the statement: `#include ` needs to be preceded by: `#define _XOPEN_SOURCE` so the function prototype is visible. or, for gcc, use parameter `-std=gnu99` or `-std=gnu11` – user3629249 Feb 06 '16 at 19:02
  • or build with `-D_GNU_SOURCE`, which is less restrictive than `_XOPEN_SOURCE` – eradman Jul 21 '20 at 14:30

1 Answers1

1

You are missing to tell us on what platform you are, your compiler version, arguments ...

In any case, strptime is not in standard C, but comes with POSIX. Probably you got your compiler options wrong such that it doesn't provide you with POSIX extensions to C. With gcc this would be to use -std=gnu11 instead of -std=c11, for example.

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177