Skip to main content
MEdgerton
Associate III
June 22, 2020
Question

Why does getdate(char*) not compile in STM32CubeIDE? I cannot find an option to enable it. Is there abother way of char* to tm struct?

I see that the standard time.h is included. But getdate to convert a char* to tm does not coliple as it is not enabled. I have tried various project options with no joy.

Can someone let me know how to do this?

This topic has been closed for replies.

6 replies

Tesla DeLorean
Guru
June 22, 2020

Doesn't compile, or doesn't link?

Assuming the latter you need to link against a full library not some limited, lite or cut-down one.

grep the library directory to find which, if any, contain the function.

Sure you could find some source if you looked too, and integrate that into the project.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
berendi
Principal
June 23, 2020

Use strptime instead.

#define _XOPEN_SOURCE
#include <time.h>
/* ... */
struct tm tm;
strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);

_XOPEN_SOURCE must be defined before the very first #include directive, not just before including <time.h>.

MEdgerton
MEdgertonAuthor
Associate III
June 23, 2020

Thank you, I found this but it generates a compiler warning " warning: implicit declaration of function 'strptime'; did you mean 'strftime'? [-Wimplicit-function-declaration]".

is there a way to stop this. I try to keep warnings to 0 so I can see any that may actually cause a problem when running.

berendi
Principal
June 23, 2020

Again,

_XOPEN_SOURCE must be defined before the very first #include directive, not just before including <time.h>

What is the first non-comment line in the source file in which strptime() is called?

MEdgerton
MEdgertonAuthor
Associate III
July 12, 2020

Many thanks, I used strptime and it works well.

Hasdf.1
Visitor II
November 18, 2020

I determined this however it generates a compiler warning caution. implicit declaration of characteristic guidedid you mean strftime? Wimplicit function-statement