ARM Technical Support Knowledge Articles

How do I import a cpp model as a shared object?

Applies to: Fast Models



Fast Models allow the instantiation and interaction with a C++ object from within a LISA+ component. This can be particularly useful when trying to integrate a model available in C++ or for using pre-compiled C++ components provided by 3rd parties. You can find more information about importing C++ models into Fast Models here. The purpose of this article is to show you how to import a C++ model compiled as a shared object instead of a static library. Please note, although this functionality is not officially supported, you can use the method described here to achieve this.

Example system

The example system attached to this article demonstrates how you can import an external memory component written in C++ into Fast Models. The top level component itself contains:

External Memory component

The source code for the external memory component can be found in the "CPPModel" folder in the example attached. To build this into a shared object, please use the following commands:

   gcc -Wall -fPIC -m32 -c  ext_mem_model.cpp

   gcc -shared -m32 -o *.o

This should build a shared library called "". Alternatively, you could use the build script provided with the example to do this. The build script can be found inside the "Linux" folder.

LISA+ System 

The top level component is in LISA+. In order to import the C++ model, you will need to make a LISA+ wrapper for this component where you can instantiate the C++ object. In this example, the wrapper component is called "extmemwrapper.lisa". Here's a snippet from the wrapper:

// Include C++ model's header file
#include "ext_mem_model.h"

PARAMETER {description("Memory Size"), type(uint32_t), default(0x10000000)} size;

// Pointer to our C++ model object
ExtMemModel * extMem;

behavior init
        //Initialise all sub-components 
// Instantiate C++ model object
extMem = new ExtMemModel(size);

// Check the memory was allocated correctly
if (extMem == NULL)
cerr << "ExtMemWrapper::init() Failed to construct ExtMemModel" << endl;

As you can see from the above snippet, you will need to includes the header file in the "includes" section and instantiate the object in the "resources" section of the wrappper. Now, in order to successfully build the system you need to link the shared library. This can be done by specifying the following in the "ADDITIONAL LINKER SETTINGS" (SystemCanvas -> Project Settings -> Linker):

 -Wl,-rpath,. -L../<Location-of-lib> -l<name-of-lib>

The important thing to note here is the "-rpath,." flag. This is telling the linker that during runtime the shared library will be in the same folder as the model. So, make sure the is in the same folder as your model (cadi library).

Now, just build the model (CADI library) from SystemCanvas!

Running the example

To run the example, follow these steps:

  1. Build the shared object using provided (Linux folder)
  2. Build the model via SystemCanvas 
  3. Run the model using model_shell and load image:

    model_shell -m <path/to/model>.so -a <path/to/image>.axf

This will load the image in the external memory, thus, showing that read and write functions to the imported external memory component is being successfully carried out. 


Article last edited on: 2013-08-27 13:36:15

Rate this article

Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential