How to build C/C++ models for VeriStand on any target OS with the Cmd

Updated Mar 4, 2021

C and C++ are popular programming languages, a common implementation of this languages is to create simulation models. It is possible to build models for VeriStand that are C or C++ based. This article is going to explain the steps required to execute to be able to build those models into a VeriStand compatible model. The article is divided into the different operating systems VeriStand can deploy applications to: Windows, Pharlap and Linux Real-Time.
 

  1. Installing the software required.
  2. Adapt your C/C++ code for building a VeriStand Model
There are three main steps that you require to perform for building a C/C++ model compatible with VeriStand:
  • Create a model.h header file.
  • Adapt template.c to serve as your model code.
  • Create a makefile to compile your model code.
​​​​​​​For More details on this steps you must consult the introduction
NI VeriStand Model Framework
on section Overview: Model Creation and Compilation Process


3. Compiling the model with NI VeriStand Model Framework and the Command prompt tools.
  • Open the Command prompt by typing cmd on Windows Search bar
  • Open Microsoft Windows x86/x64 Debug Build Environment. To do that on your command navigate to the following directory using this command: “cd C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin”
  • Windows and Pharlap Targets:
    • Enter this command to pass to a x86 environment “SetEnv.Cmd /x86”
    • Navigate to the folder your Model Files are located (model.h, makefile and model.c)(One of the shipping examples, For instance: write command: “cd C:\VeriStand\2019\ModelInterface\custom\examples\engine”
    • Use the tool nmake to build the model for example: “nmake engine.mak”​​​​​​​
    • Navigate to the folder the files are located and look for the .dll file. That file is the successful build you can import into VeriStand to run this model.
  • Linux RT 64:
    • Enter this command to pass to a x86 environment “SetEnv.Cmd /x64”
    • Navigate to the location your model source files are. For instance, C:\VeriStand\2019\ModelInterface\custom\examples\engine
    •   Once on the location Enter the following command to build a model compatible with Linux 64 bits RT targets modify the bolded section with the name of your .mk file “C:\VeriStand\2019\ModelInterface\tmw\toolchain\Linux_64_GNU_Setup.bat&s-make.exe -f engine-linux64.mk
    • Navigate to the folder the files were located and search for the .so file, that is going to be the built model that you can import into VeriStand.
​​​​​​​​​​​​​​​​​​​​​​​​​​​
  • Linux RT 32-bit ARM:
    • Enter this command to pass to a x86 environment “SetEnv.Cmd /x86”
    • Navigate to the location your model source files are. For instance, C:\VeriStand\2019\ModelInterface\custom\examples\engine
    •   Once on the location Enter the following command to build a model compatible with Linux 64 bits RT targets modify the bolded section with the name of your .mk file “C:\VeriStand\2019\ModelInterface\tmw\toolchain\Linux_ARM_32_GNU_Setup.bat&cs-make -f engine-linux.mk
    • Navigate to the folder the files were located and search for the .so file, that is going to be the built model that you can import into VeriStand.
 
Note: Make sure that you moved your .so file out of the source code folder before building for a second OS, otherwise there is a chance that building on the second time will conflict with the first build.