PDA

View Full Version : sscanf() problems on Teensy 3.0 & Windows



Jp3141
12-18-2012, 05:55 PM
This minimal example won't compile on Win7 or WinXP, but works on my Mac:



int i;
void setup() {}
void loop() {sscanf("0", "%d", &i);}

This is the error:

c:/projects/arduino-1.0.2/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.4.1/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-closer.o): In function `_close_r':
closer.c.text+0x12): undefined reference to `_close'
c:/projects/arduino-1.0.2/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.4.1/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-lseekr.o): In function `_lseek_r':
lseekr.c.text+0x16): undefined reference to `_lseek'
collect2: ld returned 1 exit status

I had posted this in the other forum, but got little response. #include'ing the stdio.h and/or stdlib.h doesn't make any difference. Anyone have a solution ?

MichaelMeissner
12-18-2012, 11:28 PM
Obviously, the best solution is to fix the library, but until it is fixed, you could add something like the following to your main program:



#ifdef __arm__
extern "C" {
int _close (int fd) { return -1; }
int _lseek (int fd, long long offset, int whence) { return -1; }
};
#endif


:cool: (hmmm, too bad this forum doesn't have :nerd:, oh well).

Jp3141
12-19-2012, 04:06 AM
Obviously, the best solution is to fix the library, but until it is fixed, you could add something like the following to your main program:



#ifdef __arm__
extern "C" {
int _close (int fd) { return -1; }
int _lseek (int fd, long long offset, int whence) { return -1; }
};
#endif


:cool: (hmmm, too bad this forum doesn't have :nerd:, oh well).

Thanks, that sort of fixes it (I guess it basically makes those calls ignored; that can't be the desired action), but the tiny sketch (your #ifdef + my example above) then compiles to 46,268 bytes; something is wrong.

Also, aren't the Arduino libraries identical across platforms ? Why is this fix not necessary on my Mac ?

PaulStoffregen
12-20-2012, 11:00 AM
I've added these, so the sprintf and sscanf should work on the next beta release.

I'm looking into other issues snprintf now.... followup here:

http://forum.pjrc.com/threads/710-Teensy-3-and-c-string-functions

Jp3141
12-21-2012, 10:04 PM
Is there a reason why it works OK on my Mac, but not on the PCs ?