- Edited
Hi! I'm attempting to load a trained model as-per this library -> https://github.com/f0uriest/keras2c
So far I can clone the Github to my Bela in a fresh project (MYPROJECT), compile the test code according to the instructions (https://f0uriest.github.io/keras2c/usage.html) using the example files provided https://github.com/f0uriest/keras2c/tree/master/example) and run that program successfully on my command line on the Bela board.
Where I fail is setting up my render.cpp to do the same thing, and I'm convinced it's due to linking issues (or maybe some c vs. c++ thing?). When I load a model in render.cpp (similar to https://github.com/f0uriest/keras2c/blob/master/example/example_test_suite.c)
Which returns this error:
example.c:(.text+0x840): undefined reference to k2c_dense(k2c_tensor*, k2c_tensor const*, k2c_tensor const*, k2c_tensor const*, void (*)(float*, unsigned int), float*)'
example.c:(.text+0x882): undefined reference tok2c_dense(k2c_tensor, k2c_tensor const, k2c_tensor const, k2c_tensor const, void ()(float, unsigned int), float)'
example.c:(.text+0x8fc): undefined reference to k2c_lstm(k2c_tensor*, k2c_tensor const*, float*, k2c_tensor const*, k2c_tensor const*, k2c_tensor const*, float*, int, int, void (*)(float*, unsigned int), void (*)(float*, unsigned int))'
example.c:(.text+0x930): undefined reference tok2c_dense(k2c_tensor, k2c_tensor const, k2c_tensor const, k2c_tensor const, void ()(float, unsigned int), float)'
collect2: error: ld returned 1 exit status
I've tried to fix the linking by using this command (inspired by a fix in the references + the instructions from keras2c repo):
make -C ~/Bela PROJECT=MYPROJECT COMPILER=gcc CFLAGS="-I/root/Bela/projects/MYPROJECT/ -std=c99" LDFLAGS="-L/root/Bela/projects/MYPROJECT/include" LDLIBS="-lkeras2c -lm /root/Bela/projects/MYPROJECT/example.c"
Notably, if I exclude the example.c reference, i get an issue with having undefined references to things defined in that file:
/root/Bela/projects/MYPROJECT/render.cpp:674: undefined reference to example_initialize()'
/root/Bela/projects/MYPROJECT/render.cpp:676: undefined reference toexample(k2c_tensor, k2c_tensor)'
/root/Bela/projects/MYPROJECT/render.cpp:677: undefined reference to example(k2c_tensor*, k2c_tensor*)'
/root/Bela/projects/MYPROJECT/render.cpp:678: undefined reference toexample(k2c_tensor, k2c_tensor)'
/root/Bela/projects/MYPROJECT/render.cpp:679: undefined reference to example(k2c_tensor*, k2c_tensor*)'
/root/Bela/projects/MYPROJECT/render.cpp:680: undefined reference toexample(k2c_tensor, k2c_tensor)
Which to me indicates some shortcoming in my approach where the compiler isn't getting the right links. I also explored using this approach: https://github.com/gosha20777/keras2cpp but the cmake version & c++17 version requirements weren't compatible and it seems like a longer journey than keras2c.
And finally, I've now noticed that if i just run rename my render.cpp to render.c all these problems go away, but then I can't seem to use things like AudioFile:
In file ./libraries/AudioFile/AudioFile.h: 'string' file not found column: 10, line: 2
Referenced posts:
https://forum.bela.io/d/629-problem-linking/2 --> really useful for command line interactions w/ bela. i tried the "first approach" without success.
https://forum.bela.io/d/2223-compiling-with-external-libraries/2 -> more insight to the make commands
https://forum.bela.io/d/2786-using-tflite-within-a-bela-project/3 -> tflite setup information