Use .so File With cRIO and LabVIEW Real-Time

Updated Nov 25, 2020

Environment

Software

  • LabVIEW Real-Time Module
  • C/C++ Development Tools

I have written code in C or C++ and want to use it as a .so file on my CompactRIO that runs Linux RT. How can I compile my written code into a .so file and how do I call it from the LabVIEW code on my cRIO?

If you want to call a function from a .so file in LabVIEW, that will be possible using a Call Library Function Node. However, the .so file will have to be compiled specifically for the real-time target you are using. This can be done from C or C++ code with a free tool, C/C++ Development Tools for NI Linux Real-Time. You can check the operating system of your cRIO from Real-Time Controllers and Real-Time Operating System Compatibility.

Following you find an instruction, what you have to do in order to compile your code into a .so file:
  • Install Java (Java SE 6 or greater is recommended), which you can download at the Java Download page .
  • Install C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition.
  • Launch C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition.
  • When prompted, select a folder in which to store Eclipse projects and click OK.
  • In the Eclipse welcome screen, select the Workbench icon on the far right to open the workbench view.
  • Create a new project in the C/C++ perspective by navigating to File>>New>>C Project and choosing a Shared Library project and the Cross GCC Toolchain
   


Project Setup.PNG

 
  • Select both Debug and Release configurations for creation
  • When prompted to configure the Cross GCC prefix and path, select the appropriate path and prefix for your NI Linux Real-Time target from the list below and displayed in the following screenshot for an Intel x64 target:
Prefix:
(ARM-based targets, 2013 software stack)
arm-none-linux-gnueabi-
(ARM-based targets, 2014 and 2017 software stack) arm-nilrt-linux-gnueabi-
(Intel x64-based targets, 2014 and 2017 software stack) x86_64-nilrt-linux-
Path:
(ARM-based targets, 2013 software stack) \<National Instruments>\Eclipse\toolchain\gcc-4.4-arm\i386\bin
(ARM-based targets, 2014 software stack) \<National Instruments>\Eclipse\14.0\arm\sysroots\i686-nilrtsdk-mingw32\usr\bin\armv7a-vfp-neon-nilrt-linux-gnueabi
(ARM-based targets, 2017 software stack) C:\build\17.0\arm\sysroots\i686-nilrtsdk-mingw32\usr\bin\arm-nilrt-linux-gnueabi
(Intel x64-based targets, 2014 software stack) \<National Instruments>\Eclipse\14.0\x64\sysroots\i686-nilrtsdk-mingw32\usr\bin\x86_64-nilrt-linux
(Intel x64-based targets, 2017 software stack) C:\build\17.0\x64\sysroots\i686-nilrtsdk-mingw32\usr\bin\x86_64-nilrt-linux
  • Now import your .c-file by right-clicking on your project folder and choosing Import. Here you can now choose your file and it is added to your project.
  • When completed, your Project Explorer pane should look like the screenshot below (in this example engine.c is the c-File we want to compile into a .so-file. model.h, ni_modelframework.c and ni_modelframework.h are only necessary if you compile your .so file for a Veristand model).


Files Added.PNG
  • Right-click your project in the Project Explorer tab and select Properties.
  • Select C/C++ Build in the left pane of the Properties dialog box.
  • Select Internal builder from the Builder type pull-down menu for the Debug configuration.
  • Select Settings under C/C++ Build in the left pane of the Properties dialog box.
  • Select Miscellaneous under Cross GCC Compiler in the Tool Settings tab. In the Other flags text box, add a space after the existing text and enter one of the following values:
(ARM-based targets, 2017 software stack) --sysroot=C:\build\17.0\arm\sysroots\cortexa9-vfpv3-nilrt-linux-gnueabi
(Intel x64-based targets, 2017 software stack) --sysroot=C:\build\17.0\x64\sysroots\core2-64-nilrt-linux
  • Select Miscellaneous under Cross G++ Compiler in the Tool Settings tab. In the Other flags text box, add a space after the existing text and enter one of the following values:
(ARM-based targets, 2017 software stack) --sysroot=C:\build\17.0\arm\sysroots\cortexa9-vfpv3-nilrt-linux-gnueabi
(Intel x64-based targets, 2017 software stack) --sysroot=C:\build\17.0\x64\sysroots\core2-64-nilrt-linux
  • Select Miscellaneous under Cross G++ Linker in the Tool Settings tab and enter one of the following values into the Linker flags text box:
(ARM-based targets, 2017 software stack) --sysroot=C:\build\17.0\arm\sysroots\cortexa9-vfpv3-nilrt-linux-gnueabi
(Intel x64-based targets, 2017 software stack) --sysroot=C:\build\17.0\x64\sysroots\core2-64-nilrt-linux
  • Navigate to C/C++ General>>Paths and Symbols in the Project Properties window. Go there to the Symbols tab and select Add. Enter a symbol of Name kNIOSLinux , press OK and afterwards Apply.


SetSymbol.PNG

 
  • In the project properties window, choose C/C++ Build>>Settings and then go the Tool Settings>>Cross GCC Compiler>>Miscellaneous section. Select the Position Independent Code option and press Apply.


PIC.PNG
  • Still in C/C++ Build>>Settings, go the Tool Settings>>Cross G++ Compiler>>Miscellaneous section. Select the Position Independent Code option too and press Apply.
 
  • Go the Error Parsers tab. Make sure that only the GNU Assembler Error Parser, GNU gmake Error Parser 7.0, and the GNU Linker Error Parser options are selected and press Apply:


error parsers.PNG

 
  • Go to C/C++ Build>>Settings>>Cross GCC Compiler and add the compiler command -fvisibility=protected to instruct GCC to set the symbol visibility to protected. Press Apply and afterwards OK to close the Properties window.
  • Select Project>>Build Project in the menu bar in order to build an executable of your project.
The resulting .so file must be is placed in a directory on the target with proper permissions via FTP or WebDAV and referred to in the LabVIEW code with the correct file path on the target.