"Undefined Reference" Error When Cross Compiling C/C++ Code That Calls NI Drivers for NI Linux Real-Time Targets

Updated Sep 3, 2025

Reported In

Operating System

  • LabVIEW Real-Time (NI Linux Real-Time)

Programming Language

  • C
  • C++

Issue Details

I am working on developing an application in Visual Studio Code (VSCODE) for my NI Linux Real-Time (RT) controller, following the instructions listed in the NI Linux Real-Time Cross Compiling: Using the NI Linux Real-Time Cross Compile Toolchain with Visual Studio Code tutorial. My code calls different NI drivers, such as NI-DMM, to perform the required functionality. When I run the "CMake Generate Build Files" task I do not get any errors, but when running "Ninja" task I always get several Undefined Reference errors. All of them seem to be related to the functions contained in the NI drivers I am using in my program, such as the one shown in the image below.

 

Solution

The error is occurring because the compiler is missing the shared library (SO) file of the NI driver that include the functions you are using in your code. To solve the issue, follow the steps below:

 

1.- Find the SO files of the NI drivers you are using, these files start with prefix "lib". Ensure you have installed the NI drivers required in your RT target and host PC.

  • You might find some SO in the following directories of your host PC like (NI DAQmx, NI System Configuration, NI Vision, NI IMAQdx).
    • for Armv7 targets: C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\arm\gcc
    • for x64 targets: C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\gcc

  • In case you could not find the SO files for the NI drivers you need, you must download those shared libraries from your RT target, these files can be found in the following directories. You can retrieve them using WebDAV or any SFTP server.
    • for Armv7 targets: /usr/lib/arm-linux-gnueabi/
    • for x64 targets: /usr/lib/x86_64-linux-gnu/
    • Other common paths: /usr/lib

NOTE: When downloading the SO files from the RT target, ensure you are not getting Symbolic Link files. You can access to the shell of your RT target and identify the actual SO files with command ls -l <searchpath> | grep -i <searchword>. Files that do not point to other files -> are the actual SO files.

 

2.- Open your CMakeLists.txt file and use the target_link_libraries function to link your binary with the SO files you have retrieved from your RT controller.

 

3.- Rerun the CMake and Ninja tasks. Sometimes the main SO library depends on auxiliary or secondary SO libraries that must be added as well to the CMakeLists.txt through the target_link_libraries function. You can try the commands below in order to find the missing auxiliary dependencies.

  • ldd: Useful to display the dependencies of a shared library or binary file.
    • You can install it in your RT target through opkg install ldd
    • To display SO dependencies ldd <yourSOfile>

  • readelf: Useful to display functions included in a shared library.
    • To display SO functions readelf -Ws <yourSOfile>, you can filter the output with | grep -i <searchword> to search the undefined reference of the function you are missing.