Adding a library to your DI agent

While developing a DI agent you often need to include one or more pre-written libraries as part of your code. as part of your agent.

For example, suppose you have a library libhello.so along with it's header file:

libhello.so.

hello.h

Using these as an example, you'll perform these steps:

  1. Copy the header file to the correct location.

  2. Copy the library file to the correct location.

  3. Edit the CMakeFile.txt to include the library file.

  4. Edit the source code to use the library.

  5. Build, run, and test your library.

Here is each step shown using hello.h and libhello.so as examples:

  1. In your source tree, copy your header file to the include directory:

    include/hello.h.

  2. In your source tree, copy the libhello.so to config/urs/lib:

    config/usr/lib/libhello.so

  3. Edit the CMakeLists.txt to include your new library:

    set(MY_SHARED_LIB ${CMAKE_CURRENT_SOURCE_DIR}/config/usr/lib/libhello.so)

    if(NODAEMON)

    target_link_libraries(ThirdPartyReferenceAgentHS_Daemon PRIVATE AgentAPI pthread ${MY_SHARED_LIB})

    else()

    target_link_libraries(ThirdPartyReferenceAgentHS_Daemon PRIVATE AgentAPI pthread ${MY_SHARED_LIB})

    endif()

  4. Edit your source code:

    #include <hello.h>

    int main(...) {

    ....

    hello();

    ...

    }

  5. Build your code. Here is an example using emu-tool:

    $ ./clean.sh

    $ ./setup_v2_build_environment.sh TargetRelease

    $ ./build.sh

    $ ./pack.sh

    $ emu-tool create-nic mynic

    $ emu-tool agent-install mynic

    $ emu-tool attach mynic

    Attaching to mynic

    (type exit to exit the container)

    BusyBox v1.28.3 (2020-05-27 21:11:36 UTC) built-in shell (ash)

    Enter 'help' for a list of built-in commands.

    / # ls /usr/lib/libhello.so

    /usr/lib/libhello.so

    / #

    / # /usr/bin/2302fff1/ThirdPartyReferenceAgentHS_Daemon

    d3-hs-sub

    Demo of High-Speed Metrology Subscription

    hello

    ...