Summary:
Code that calls a std::function will fail to build with a linking error that reports
Code: Select all
"Error: Meta information ("_ZNSt3__110__function6__funcIPFffENS_9allocatorIS3_EES2_EclEOf.nstackwords") for function "_ZNSt3__110__function6__funcIPFffENS_9allocatorIS3_EES2_EclEOf" cannot be determined."
Context:
I'm porting this multi-layer perceptron library to XMOS:
https://github.com/MusicallyEmbodiedML/MLP_XMOS
Reason: we want support for backprop and training on the chip. (TFLite won't cut it.)
I had a successful build, including all unit tests, when wrapping it in a helloworld-style main.c built by hand with xcc. I've now built the MLP code as a static library and integrated it into the "Bare metal/explorer board" example from the xcore_iot framework:
https://github.com/MusicallyEmbodiedML/ ... orer_board
When I run a test with PJOB() on Tile 0 alongside other demo apps, it fails to build. By #if 0'ing the code, I've narrowed it down to the two calls to std::functions.
Searching for the error, this thread appears:
https://www.xcore.com/viewtopic.php?f=1 ... tion#p8537
It seems to apply to function pointers - std::function being a glorified version of them under the hood I suppose.
However, the same error appeared to me with another toy library I wrote (which would just generate a test sine tone). It's a C++ code and a C wrapper built as a static library. I cannot get it to build unless I either specify the #pragma stackfunction of all C wrapper functions, or move the C wrapper code from the library to the example project, leaving no extern "C"-declared function signature in the static library.
Do I really just suck it up and work around it? Function pointers are really useful for my use case - each layer will have a different user-configurable activation function, which specifies a derivative in the backprop. Even having crude C function pointers is better than "if this then call this, etc...". I've used function pointers in bare-metal ARM M0 with no memory manager and no heap, so what am I missing here?
Thanks for any replies!