[SOLVED] shared library in Segger Embbeded Studio

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] shared library in Segger Embbeded Studio

    Hi everyone,
    How to add a file.dll to a project ?
    I have a shared library with my file .dll and I would like to integrate it into my project with a Nordic nrf5 board.
    But in "options" tab , I don't see anything to add. ?(
    In the manual, I saw that there were macros :
    $(HostDLL)
    $(HostDLL) – String
    The file extension for dynamic link libraries on the CPU that SEGGER Embedded Studio is running on e.g. .dll.
    $(HostDLLExt)
    $(HostDLLExt) – String
    The file extension for dynamic link libraries used by the operating system that SEGGER Embedded Studio is running on e.g. .dll, .so, .dylib.



    Do you think we can add this type of file in the "LINKER" tab or "PREPROCESSOR" tab of the "Options" tab of project?
    If not, how can we do it?

    Best regards
  • > ... I would like to integrate it into my project with a Nordic nrf5 board.

    It would be really new to me that the mentioned target platform supports shared libraries a.k.a. DLLs.
    That would require a MMU and a respective OS that can run multiple applications simultaneously.

    In a Cortex M context, libraries for the target system are merely collections of code (functions) and associated data.
  • Hello,

    Thank you for your inquiry.
    As _frank_ correctly stated dynamic libaries on bare metal embedded systems is highly atypical.
    Usually you link only statically on embedded systems (.a files + their respective headers).
    For dynamic linked libraries you essentially need a fully fledged OS like Linux running or at least an RTOS, Filesystem and most likely an MMU.
    Also your dll would need to be build for your target system architecture.

    If I had to guess none of these prerequisites fit your setup. Also if it did, the dll would simply reside on your Filesystem as a binary blob and your OS would need to figure out how to load it. It has nothing to do with Embedded Studio.
    If you have a static library you can simply set it in project options under Additional Input Files.
    Just make sure that your library header is also included under User Include Directories.

    So maybe it would make sense if you could explain what you are exactly trying to do?
    Which library are you looking to add to your project?
    Do you have the sources? If yes, then build it as a static library and add it to your project as mentioned above.

    Best regards,
    Nino
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello,

    Thank you for your reply.

    However it is a static library written in C that calls functions in C++. (Tensorflow Lite C API).

    github.com/tensorflow/tensorfl…/master/tensorflow/lite/c
    tensorflow.org/lite/guide/buil…tensorflow_lite_c_library

    First, I integrated it in my project (in C language with all nordic library) by adding the paths of the library in "preprocessor". To test, I simply wrote a hello word :
    **********************************************************
    #include <stdio.h>
    #include <tensorflow/c/c_api.h>
    #include <stdlib.h>

    int main(void) {
    printf("Hello from TensorFlow C library version %s\n", TF_Version());
    return 0;
    }

    **********************************************************

    But I get the following error:

    undefined symbol TF_Version referenced by symbol main (section .text.main in file main.o)

    Then I tried to build my library with cmake, which generated tensorflowlite_c.dll :
    cmake ../tensorflow_src/tensorflow/lite/c
    cmake --build . -j



    Best regards,
  • scp_011997 wrote:

    First, I integrated it in my project (in C language with all nordic library) by adding the paths of the library in "preprocessor".
    That's not enough.
    I suppose you require this preprocessor setting for the API header(s).

    But you will also need to add the actual library (usually *.a) to the linker settings.
    Usually here:


    Not sure if this library comes with precompiled libs/binaries.
    If not, you need to add is as a library project and compile it yourself.
  • ok,
    yes, I agree with you, in SES, I add all necessary path for my project in "Options project > Code > Preprocessor > User Includes Directories".
    But, According to the documentation (tensorflow.org/lite/guide/buil…tensorflow_lite_c_library),

    I generated a TensorFlow Lite C API shared library with the following commands cmake. This generated the following file "tensorflowlite_c.dll".
    I add my library but it's not type *.a but *.dll . (see image.png)

    cmake generated not library *.a

    Also, according to Tensorflow, I added the necessary headers (c_api.h, c_api_experimental.h and common.h) to use the generated shared library.

    But I still have this error.


    can I convert *.dll to *.a ?

    but I think we're just moving the problem

    best,
    Images
    • Capture.PNG

      66.76 kB, 1,319×672, viewed 213 times
  • > can I convert *.dll to *.a ?
    I would think, probably not. The DLL (shared lib) is build for a specific platform that supports this libraries (*.dll/*.so).
    Even if based on ARM, it surely requires an A processor (Cortex A).
    AFAIK Nordic nRF5 is Cortex M, so it fails already for the missing ARM instruction support (Cortex M is Thumb/Thumb II only).

    And if you mean that : en.wikipedia.org/wiki/TensorFlow
    It says :

    Which means, the library will contain calls to system libraries of the underlying platform (POSIX, Win32, Android).
    I suppose you need a bare-metal version of such alibrary.
  • Hi,

    After some research, I realized that I was wrong: I don't need Tensorflow Lite C API but Tensorflow Lite For Microcontroller (TFLM) '-_-.
    I started with a simple main.cpp before switching to c.
    So I generated my static library:
    I installed an Ubuntu WSL to make the TFLM makefile.
    I got the *.a file and I added it in "Project Option > Common > Code > Linker > Additional Input file : ../../libtensorflow-microlite.a
    I also added the paths of TFLM.
    I added libtensorflow-microlite.a in a project folder.


    Without adding the basic TFLM library, I wanted to build to check. I got no error but a worrying warning
    "/lib/libtensorflow-microlite.a does not exist"

    If I add the basic lib :
    #include "tensorflow/lite/micro/all_ops_resolver.h"
    #include "tensorflow/lite/micro/micro_error_reporter.h"
    #include "tensorflow/lite/micro/micro_interpreter.h"
    #include "tensorflow/lite/schema/schema_generated.h"


    he says he can't find them.
    Despite the link of the *.a file, why the project build does not see it?
    And how to fix this problem?
    Best,
    Images
    • Capture.PNG

      16.99 kB, 611×294, viewed 180 times
  • > After some research, I realized that I was wrong: I don't need Tensorflow Lite C API but Tensorflow Lite For Microcontroller (TFLM) '-_-.

    That makes sense, I guess.

    > Without adding the basic TFLM library, I wanted to build to check. I got no error but a worrying warning
    > "/lib/libtensorflow-microlite.a does not exist"

    Is there any such library, i.e. *.a file ?
    Or are you suppsed to build it yourself ?
    I would check the readme files and documentations.

    > If I add the basic lib :
    > #include "tensorflow/lite/micro/all_ops_resolver.h"
    > #include "tensorflow/lite/micro/micro_error_reporter.h"
    > #include "tensorflow/lite/micro/micro_interpreter.h"
    > #include "tensorflow/lite/schema/schema_generated.h"


    > he says he can't find them.
    > Despite the link of the *.a file, why the project build does not see it?
    > And how to fix this problem?


    Your terminology suggests you have not much experience with embedded toolchains.
    These files you added were not the "library", but just headers.
    I suppose to declare it's API, i.e. functions to call when using this library.

    They need to be added to the project separately, usually in the Preprocessor / User Include Directories:

    Be aware that you need to add them to the Debug and Release project separately (as with the lib itself).
    Or select "Common" from the "Private configurations" in this tab, and set them for both at once.

    > #include "tensorflow/lite/micro/all_ops_resolver.h"

    I would add the path including '../tensorflow/lite/" to the include paths, either relative or absolute, and reference them as follows in the project:
    #include "micro/all_ops_resolver.h"

    [i]The preprocessor combines the given path/filename in the #include diective with all specified include paths, and opens/uses the first file it finds.[/i]