Rob Avery IV
Rob Avery IV

Reputation: 3730

strptime giving "implicit declaration" and "undefined reference"

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.

Upvotes: 2

Views: 4596

Answers (1)

Jens Gustedt
Jens Gustedt

Reputation: 78903

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.

Upvotes: 2

Related Questions