Linking OS-IoT in to Your Own Applications

The main value of OS-IoT is not to use the command-line demo application, but instead to link the library with your own applications. The lack of a standard configuration for building C++ programs means that there are many different ways you might link the library.

On this page, we will give an example based on including a dynamically linked version of OS-IoT. We assume you have created a project directory (<project directory>) to contain source files for your new application.

# Enter your OS-IoT directory
$ cd <os-iot directory>

# If desired, you can edit the file “onem2mdefaults.hxx” to contain suitable defaults for your application.
# Default values can be overwritten in code if you prefer not to edit this file.

# Make the library (.so) file for your architecture
$ make libosiotdyn

# Copy files needed to your new project
$ cp CDT-*.hxx onem2m.hxx <project directory>
$ mkdir <project directory>/cdt
$ cp cdt/*.hxx <project directory>/cdt/

You can now build your new application using the API exposed in onem2m.hxx.
To link your application include the link options:

-Wl,-rpath=. -L. -losiot -lssl -lcrypto -lxerces-c -lcurl -lpthread
# For example:
$ c++ -o test test.o -Wl,-rpath=. -L. -losiot -lssl -lcrypto -lxerces-c -lcurl -lpthread

The first option sets the “rpath” which determines where the linked application will look for dynamically linked libraries. The second option sets the location the linker will look for libraries. The remainting options list specific libraries needed (note that the order of the library linkage is significant because of the dependences of libosiot).