Converting Linux SDK Makefile to Cmake

Hi Edge Impulse Team,

in my project I work with Conan / CMake and thus I cannot easily switch to GNU Makefile. Therefore I decided to translate the Makefile into a CMake file (https://github.com/LagLukas/EdgeImpulseCMake).
I use it combined with the Linux SDK (https://github.com/edgeimpulse/example-standalone-inferencing-linux) and the auto generated code. Thus the only difference is that i use CMake instead of GNU Make.

It works fine If i do not use any full tf lite and easier models (such as for my project 58571). However, If I switch to a slightly more complicated network (such as project 74857) then the code still compiles but the application aborts (this does not happen with makefile). Further, the tflite support does not seem to work (as I can set it with an EON compiled model without an issue).

Could you please help me fix my two issues?

Regards

Lukas

Hi Lukas

  • Just to confirm, you’re saying that it will build, but when you run it, the application crashes/aborts?

First off, to make your life easier, did you notice that our library export comes with a CMakeLists.txt file? You can include the EI SDK by just using the add_subdirectory() function.

Second, it will be easier to help you debug if you include libraries the same way we do in the makefile. Instead of using find_library, can you include the libraries the same way we do in our makefile, by using linker flags like “-ltensorflow-lite”

I suspect this is the difference in why building with make works, but building with CMake causes you to crash.

I believe these are the linker flags you will need to load the right libraries (in addition to the ones you already have in your CMake file):

-L./tflite/linux-x86 -Wl,–no-as-needed -ldl -ltensorflow-lite -lcpuinfo -lfarmhash -lfft2d_fftsg -lfft2d_fftsg2d -lruy -lXNNPACK -lpthread

Hi @AlexE,

Yes it builds and for certain projects it runs just fine and for some it crashes (as mentioned above).

I would also be very open to use your CmakeLists.txt but I somehow failed to use it. Could you please provide an example (e. g. to build camera app with full tflite and armv7 processor?).

I will try out your comment and come back on you, but I think if you show me how your Cmake approach works then this would be way easier.

Regards

Lukas

Hi Lukas,

I actually don’t have a CMakeLists.txt for Linux, otherwise I would happily share :-). I’m pulling from a cmake build for another embedded target altogether, and really the only common line between that project and yours is the easiest way to include the EI SDK.

Note, you can’t use the CMakeLists.txt file that comes with the export directly. It’s meant to be included via add_subdirectory(). So for example, if you copy the exported files from Studio in the directory “source”, then "add_subdirectory(source) " is what you want inside your CMake file.

Note our CMakeLists.txt file expects the target “app” to exist, so you need to place add_subdirectory AFTER your line “add_executeable(app…)”

If you want to give this a shot and push your changes to your repo, I’m happy to have a look if you’re still having issues when you’re done!

Hi Alex,

thanks once more for the fast reply. I tried out your approach and I end up with some linking issues (but might be my fault as I am Pyhton dev, not C++). I am pretty sure you see it quite easily.

See the status I tried out here:

and the CMake File according to your comments:

but even If I do not consider the linking issue: How could I select a hardware achitecture and the full tflite flag?

Regards

Lukas

Note the camera.cpp has no dependencies except the Edge Impulse libs.

@AlexE
I could fix my original CMakeFile. It crashed as I had a different linking order than you did. If it is desired from EdgeImpulse then I would be open to share the file with you guys.

Glad to hear you got things working! Yes please do share the file, as both EI and the forum community would love to have a CMake for Linux example!

I put it here: LagLukas/EdgeImpulseCMake (github.com)

2 Likes