[SOLVED] Problems using libraries implemented in cpp

Hi!,
i’m trying to compile/flash a .ino code deom Particle web IDE (firmware version 0.6.3) including some functions from a library implemented in cpp, and i am having the following errors … any clue about where the problem/s can be? thanks a lot!

/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7-m/libg_nano.a(lib_a-writer.o): In function `_write_r':
writer.c:(.text._write_r+0x10): undefined reference to `_write'
/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7-m/libg_nano.a(lib_a-closer.o): In function `_close_r':
closer.c:(.text._close_r+0xc): undefined reference to `_close'
/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7-m/libg_nano.a(lib_a-fstatr.o): In function `_fstat_r':
fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'
/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7-m/libg_nano.a(lib_a-isattyr.o): In function `_isatty_r':
isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'
/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7-m/libg_nano.a(lib_a-lseekr.o): In function `_lseek_r':
lseekr.c:(.text._lseek_r+0x10): undefined reference to `_lseek'
/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7-m/libg_nano.a(lib_a-readr.o): In function `_read_r':
readr.c:(.text._read_r+0x10): undefined reference to `_read'
collect2: error: ld returned 1 exit status
../../../build/module.mk:222: recipe for target 'target/workspace.elf' failed
make[1]: Leaving directory '/firmware/modules/photon/user-part'
make[1]: *** [target/workspace.elf] Error 1
../build/recurse.mk:11: recipe for target 'modules/photon/user-part' failed
make: *** [modules/photon/user-part] Error 2

Would be good to know which demo.

You could also post a link to a project snapshot via the SHARE THIS REVISION button
https://docs.particle.io/guide/getting-started/build/photon/#sharing-your-app

Hi @ScruffR … sorry, i though it could be a general problem with a clear answer … the code is this, despite to be fair, the code adaptation is far to be complete. thanks

https://go.particle.io/shared_apps/5a9d40a18687ca7d5600153d

This seems to be an issue with the compiler/linker.
I’ve replaced all the includes that already are part of Particle.h by just that one header but still get the same error.
Your code doesn’t seem to use any of the functions the linker complains about and armv7-m should not be used at all IMO.

Maybe @rickkas7 can have a look.

In svm.cpp, change this function:

static void print_string_stdout(const char *s)
{
	//fputs(s,stdout);
	//fflush(stdout);
	Serial.print(s);
}

And also do something with all of the printf calls. I did a global search and replace of printf to Serial.printf, but if you do that, also include “Particle.h” and then it should compile and link.

Most of the time when you get this:

/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7-m/libg_nano.a(lib_a-writer.o): In function `_write_r':
writer.c:(.text._write_r+0x10): undefined reference to `_write'
/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7-m/libg_nano.a(lib_a-closer.o): In function `_close_r':
closer.c:(.text._close_r+0xc): undefined reference to `_close'
/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7-m/libg_nano.a(lib_a-fstatr.o): In function `_fstat_r':
fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'
/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7-m/libg_nano.a(lib_a-isattyr.o): In function `_isatty_r':
isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'
/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7-m/libg_nano.a(lib_a-lseekr.o): In function `_lseek_r':
lseekr.c:(.text._lseek_r+0x10): undefined reference to `_lseek'
/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7-m/libg_nano.a(lib_a-readr.o): In function `_read_r':
readr.c:(.text._read_r+0x10): undefined reference to `_read'

It’s because there’s a printf or other stdout/stderr call which is not supported on the Particle platform.

4 Likes

Hi @ScruffR and @rickkas7 … i’ll try that and report if it works. thanks a lot for your help & support … as always. thanks

1 Like

Hi @ScruffR … where can i check the includes that already are part of Particle.h? thanks

IIRC - since I’ve already removed the test code - I got rid of all the includes but #include <math.h> and only added #include <Particle.h> and I still didn’t get any compiler errors.

1 Like

Hi @ScruffR @rickkas7 … your suggestions work great!. thanks!

1 Like