-
-
Notifications
You must be signed in to change notification settings - Fork 86
The strnlen() C Function Is Not Available #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It looks like this is because the compile command line includes There is a standard string.h with Hmm. It's inside conditionals: #if __POSIX_VISIBLE >= 200809 Ahh. A bit of brute force says that __POSIX_VISIBLE gets set based on _POSIX_C_SOURCE, which defaults to 200809 unless _XOPEN_SOURCE is set less than 700. (in sys/features.h) For some reason, the R4 build line includes a -D_XOPEN_SOURCE (SAMD doesn't define it at all.) I don't know if that's intentional, or if someone thought that it means "Open Source" in the sense of OSSW. (I dont think that that's what it means!) (I can't find anything in the Arduino R4 core, the Arduino-api core, or the Renesas fsp code, that actually references _XOPEN_SOURCE This does imply that the problem is in the #include files, and the function is actually present in the C library that is linked in. So a workaround is simply to provide an explicit prototype like: extern "C" size_t _EXFUN(strnlen,(const char *, size_t)); |
The definition is needed by time.h (see arduino-libraries/MKRGSM@019b0e1) but we missed to give it a proper value :| Defining to 700 is ok for POSIX 2017, so strnlen prototype gets picked up Fixes arduino#18
@aentinger, I updated the platform.txt file with the -D_XOPEN_SOURCE=700 options and successfully tested my sketch using the PubSubClient library. |
Confirmed to be working in production 1.0.4 tag. |
@woolseyj thank you for tracking this down to resolution. I am still having the
Are there any additional steps that I need? |
Dear James Emerson,
You can use this one here temporarily, if you do not necessarily NEED that
it must be included in the original library?
size_t strnlen(const char *s, size_t maxlen) {
const char *end = memchr(s, '\0', maxlen);
return end ? (size_t)(end - s) : maxlen;
}
This ought to work well. It has been tried other places before. Check it
out if it is the way you'd want it. You can create a #pragma message()
directive on it, to remind you that when the error has been corrected then
you'll comment it out.
Sincerely Yours,
David Svarrer
…On Tue, Sep 19, 2023 at 9:03 PM James Emerson ***@***.***> wrote:
Confirmed to be working in production 1.0.4 tag.
@woolseyj <https://github.com/woolseyj> thank you for tracking this down
to resolution. I am still having the 'strnlen' was not declared in this
scope; did you mean 'strlen'? errors when using the pubsubclient
<https://github.com/knolleary/pubsubclient> library. I'm wondering if I
need to force a new version of renesas-ra ? I've created a new project
(which I thought would install the latest renesas-ra). I also tried adding
this to my platform.ini in platformio.
build_flags =
-D_XOPEN_SOURCE=700
Are there any additional steps that I need?
—
Reply to this email directly, view it on GitHub
<#18 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUI6JVQQP46LOOA6B7O4ZJTX3HM5NANCNFSM6AAAAAAZZ7QU5A>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Hi all. Discussion of fixing the problem in PlatformIO is off topic here. You are welcome to continue the discussion in an appropriate channel such as Arduino Forum or the PlatformIO forum |
It appears that several C functions, e.g.
strnlen()
andstrdup()
, defined in the AVR based cores are not available within the Renesas core.Both of the following statements work on an Arduino Uno WiFi Rev2 board but the second statement does not work on the new Arduino Uno R4 WiFi board.
I came across this issue by trying to compile a sketch that uses the PubSubClient library.
Please see The strnlen() C Function Is Not Available topic within the Arduino Forum for more information.
The text was updated successfully, but these errors were encountered: