Example 1: Call a Shared Library That You Built

LabVIEW 2018 Help


Edition Date: March 2018
Part Number: 371361R-01
View Product Info

DOWNLOAD (Windows Only)


LabVIEW 2015 Help
LabVIEW 2016 Help
LabVIEW 2017 Help
LabVIEW 2018 Help
LabVIEW 2019 Help

This section describes the tasks necessary to complete the Array Average VI you started building in Building a Shared Library to Call from LabVIEW so the VI can call the avg_num function in myshared.dll.

Note   (Linux) The shared library file has a .so extension. You cannot call functions in static libraries (.a files) on Linux. You can only call shared libraries (.so files) dynamically.

You must complete the following tasks before the Array Average VI can call the avg_num function in myshared.dll.

Complete Configuration of the Call Library Function Node

Note  If you want to run applications or shared libraries created with different versions of LabVIEW on the same computer, the computer must have a version of the LabVIEW Run-Time Engine that is compatible with each version of LabVIEW used to create the applications or shared libraries.

Complete the following steps to complete the configuration of the Call Library Function Node.

  1. Open the Array Average VI block diagram.
  2. Right-click the Call Library Function Node and select Configure from the shortcut menu to open the Call Library Function dialog box.
  3. Click the Browse button to the right of the Library Name or Path control to display a file dialog box.
  4. Navigate to the location of your myshared.dll file.
  5. Select myshared.dll and click the Open button. The file path to myshared.dll appears in the Library Name or Path control. The Library Name or Path control specifies the library name or path for the function you are calling. Enter only the library name if the library is in the search path of the system. Enter the entire path if the library is not in the search path of the system.
Note  To make the reference platform independent, use the * wildcard. Keep the C++ compiler from introducing platform dependence in exported function names through a process called name mangling by using the C++ compiler function export directive, extern "C"{}, in your header file.

Build the Front Panel Window

Complete the following steps to create the front panel of the Array Average VI.

  1. Place an array control on the front panel window and label it Array.
  2. Place a numeric control in the array shell and resize the array to contain four elements.
  3. Right-click the Array control and select Representation»Single Precision from the shortcut menu.
  4. Place a numeric indicator on the front panel window and label it Avg Value to display the result of your averaging calculation.
  5. Right-click the Avg Value indicator and select Representation»Single Precision from the shortcut menu.
  6. Place a numeric indicator on the front panel and label it Error to display any errors that your VI generates.
  7. Right-click the Error indicator and select Representation»Long from the shortcut menu.

The following front panel belongs to the Array Average VI.

Complete the Block Diagram

Complete the following steps to complete the block diagram of the Array Average VI.

  1. Wire Array to the a input of the Call Library Function Node.
  2. Place an Array Size function on the block diagram.
  3. Wire Array to the input of the Array Size function.
  4. Wire the Array Size function output to the size input of the Call Library Function Node.
  5. Right-click the avg input of the Call Library Function Node and select Create»Constant from the shortcut menu. Set the constant value to zero.
  6. Wire the avg output of the Call Library Function Node to Avg Value.
  7. Wire the error output of the Call Library Function Node to Error.

The following block diagram shows the completed Array Average block diagram.

Run the VI

On the front panel, enter values in Array and run the VI to calculate the average of those values. Save your work and close the VI.

If your shared library returns incorrect results or crashes, verify the data types and wiring to see if you wired the wrong type of information.

WAS THIS ARTICLE HELPFUL?

Not Helpful