How to link with external interfaces or libraries when writing my own Arduino library?

Hi!

I have trained an ML model and converted it into C/C++ executables with the help of TensorFlow C API. (see Deploying Tensorflow 2.1 as C/C++ executable). In this way I can run the inference in C/C++ environment.

Then I want to run the model in a microcontroller. I am using Arduino Nano Every so I chose Arduino IDE. I’m thinking of converting this executable file into a library so that I can give my input -> use the library and its function -> get the inference in Arduino IDE.

But when I want to write my Arduino library ( I refer to this post: Create Your Own Arduino Library ). Seems like to create a library only needs to write a header file and a .cpp file.

So I am wondering when this file is compiled and if it is possible to link the library to the external API (in my case TensorFlow C API).
or Can I write the pre-compiled C++ library (e.g. convert to .so) and use it in Arduino?

I am new to Arduino and C/C++. So your answer and suggestion will be highly appreciated! Thanks :slight_smile:

not that i know of

the .cpp has the external and internal functions and variables. the .h declares the external interfaces (functions). any other code (.cpp or .ino) can references those functions by including the .h

why would you want this to be "pre-compiled"? the IDE will compile it once for your sketch and reuse the compiled version until you move to the next project

I am thinking to compile the .cpp file so that I can link with external libraries, in my case the tensorflow C API.( for example, use gcc -L/library... ). If it is not compiled, the IDE cannot find the API.

using the IDE, you would copy your tensorFlow source files either into a library you create or your build directory.

at least with the Arduino IDE, libraries are stores as source because they can be built for different processors when the application is built. it's not like a library (.a) on your laptop where it makes sense to only compile the library once

have you checked https://www.arduino.cc/reference/en/libraries/arduino_tensorflowlite/ ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.