strptime giving “implicit declaration” and “undefined reference”

≯℡__Kan透↙ 提交于 2019-12-11 12:35:43

问题


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.


回答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.



来源:https://stackoverflow.com/questions/35234152/strptime-giving-implicit-declaration-and-undefined-reference

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!