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:
-
Copy the header file to the correct location.
-
Copy the library file to the correct location.
-
Edit the
CMakeFile.txt
to include the library file. -
Edit the source code to use the library.
-
Build, run, and test your library.
Here is each step shown using hello.h and libhello.so as examples:
-
In your source tree, copy your header file to the include directory:
include/hello.h
. -
In your source tree, copy the
libhello.so
toconfig/urs/lib
:config/usr/lib/libhello.so
-
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()
-
Edit your source code:
#include <hello.h>
int main(...) {
....
hello();
...
}
-
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
...