Background: I'm building my libraries to be as portable as possible across platforms, but working with the Arduino IDE and the various supported MCUs, I'm not so sure I'm succeeding.
Here's one example.
If my target is an M0 Pro and the following is compiled, I get no error:
#ifndef DateTimeBuilder_h
#define DateTimeBuilder_h
#include <cstdint>
#include <cstdbool>
#include <cstdio>
#include "DateTime.h"
class DateTimeBuilder
{
// declaration, declaration, declaration...
};
#endif
Great, I like it!
If I target a Due, however, the output is:
error: '::printf' has not been declared
My class uses sprintf() to print a selected format for a given DateTime, which is a member of .
If I alter the header's #include to <stdio.h>, no error happens for either.
If I target an Uno or Mega MCU, the compiler emits the message:
cstdint: No such file or directory
Now it's versus <stdint.h>. This is a bigger problem, since every library I write declares atomic types as fixed word sizes (int16_t and int32_t instead of int and long, for example) so I can guarantee type conformity when compiling across different architectures. The code written is in C++ and I'd like to not have to use deprecated declarations nor revisit every header file and replace #includes.
Is there another way around this?
I have a library (openGLCD) that uses some xxprintf formatting as it includes a "printf" type method.
It was a long time ago but I do remember running into that type of error, I can't remember the cause but I never could use the name printf as a method in my class. I ended up using the name Printf instead.
I also ran into header file issues across the platforms.
My code calls vsnprintf() rather than sprintf() but I doubt that will make difference for this type of issue.
I have this for my includes as there were some include issues for some architectures.
#ifdef __AVR__
extern "C"
{
#include <stdio.h>
}
#else
#include <stdio.h>
#include <stdarg.h> // ARM tools don't include this in stdio.h WTF!
#endif
--- bill
Thanks! That worked. edit, except for the Due compile, which I'm still getting the "error: '::printf' has not been declared" output.
Is there a reference about which architectures require which alternative headers? Or do I just need to keep building conditional header includes as I go?
My stuff compiles on Due ok.
Do you have a function or method in a class named "printf" ?
I had lots of issues when I had a printf() method in my class. I can't remember the exact issue but I was unable to work around it.
--- bill
The class in question is entirely sprintf(). I searched through the rest of the project's files and didn't find a single reference to printf().
I may have found the issue.
The full compiler output was this:
c:\users\myname\appdata\local\arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1\arm-none-eabi\include\c++\4.8.3\cstdio:122:11: error: '::printf' has not been declared
I hopped into the cstdio file at that location and deleted this line:
#undef printf
Doing so fixed compilation. My Due hasn't arrived yet for testing, but I'll update the this thread if a similar issue shows up.
Curiously the comment at the top of the body of #undef statements read:
"Get rid of those macros defined in <stdio.h> in lieu of real functions."
Perhaps the printf() replacement was neglected?
my cstdio has this on line 22:
using ::printf;
My stdio at that location has it too, but the statement was preceded by the #undef block.
This nearly empty program failed to compile to a Due target when calling sprintf()
#include <cstdio>
void setup() {
// put your setup code here, to run once:
char * buf = {"fred"};
sprintf(buf, "%s");
}
void loop() {
// put your main code here, to run repeatedly:
}
Once I removed the #undef, it compiled. I'll see if the programs work with the Due when it arrives.
Still no working compile for the Due. I'm using versions 1.8.7 and 1.8.8 with the same output.
What version compiles successfully for you?
Fixed it. I reinstalled the IDE and replicated my steps in post #4.