RESOLVED: Linker error

Hi. Got a curly one … for @zachary, perhaps?

I have a project with a separate .cpp file (added in src/ which has a function that makes a call to, simply …

#include "application.h"
 char c =;

This is causing a linker failure …

.../sparkcore/gcc-arm-none-eabi-4_8-2013q4/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/lib/armv7-m/libg.a(lib_a-readr.o): In function `_read_r':
readr.c:(.text._read_r+0x10): undefined reference to `_read'

… along with similar errors for _write, _lseek, etc, being typical of trying to use printf/scanf etc in an embedded environment, where the low level functions _write, _read etc have not been defined. These are in fact defined in src/newlib_stubs.cpp. However, should not be going anywhere near those in the first place. works fine if I have it in application.cpp.

Having spent over an hour trying to track this oddball down, I am finally stumped.

NOTE: I just wrote a bare bones test project, to try and reduce this fault in its most basic, repeatable form. But it works under those circumstances. So there must be something else in my rather large project that is somehow causing the problem.

Thanks for any help.

RESOLVED: Would you believe, there was a call to fflush(stdout). Good grief. (Yes, I’m porting someone else’s code.) Amazing how one so often finds a solution, moments after posting on a forum for help! :stuck_out_tongue:


Another case of Rubber Duck Debugging. :smile:

I couldn’t count the number of times I’ve found the solution to a problem just minutes after sending a long, detailed explanation to a mailing list or forum. Often, just taking the time and concentration to try explaining the problem to somebody else in detail is enough to kick your brain in the pants.