- Before attempting to cross-compile ANSI C NI-DAQmx examples, it is highly recommended to familiarize yourself with cross-compiling for Linux RT by going through parts 1 through 4 in the cross-compiling guide in the NI Linux Real-Time user group. This will ensure you have the necessary software downloaded, familiarize you with the Visual Studio Code environment, and give you a template to use for cross-compiling ANSI C NI-DAQmx projects for NI Linux RT. The template created in the aforementioned guide will be the base for the subsequent steps.
- Once you have completed the steps in the guide mentioned above, create a new directory to serve as the top-level directory for your NI-DAQmx project, and copy your template project into this new directory. Launch Visual Studio Code, and open this new folder with the File >> Open Folder option.
- Create a new source code file in the .src directory titled <Name of NI-DAQmx Example>.c and save the file - for this example, the ReadDigPort NI-DAQmx example will be used. These examples can be found at C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C on your computer if you installed NI-DAQmx C Support when installing the NI-DAQmx driver. Open the .c file for the example you are trying to cross-compile, and copy the contents of the example's .c file into the new .c file in the Visual Studio Code project. Save the file.

- We will need to make some edits to the template files before building and cross-compiling this code. Specifically, we will need to edit CMakeLists.txt and c_cpp_properties.json in the template in order to ensure the NI-DAQmx dependencies are properly linked.
- In c_cpp_properties.json, edit the "includePath" section so that it looks like the below screenshot, which will allow us to resolve editor errors related to dependencies/linking:
Also, be sure to edit the "program" field in launch.json so that it reflects the name of the project you're trying to build. For example, for ReadDigPort, the line would look like:
- In CMakeLists.txt, edit the section dictating the root paths for CMake Find so that it looks like the below screenshot:
Also, edit the "project specific information" section so that it looks like the below screenshots, which will allow us to include the necessary NI-DAQmx dependencies during the build:
Note that there are two ways to include the necessary dependent libraries and header files: hard-coding the paths on your system, or using the
find_ function in CMake to search for the files in your computer. Hard-coding the paths is generally easier, but makes the solution unique to a single system and less robust. In the above screenshot, hard-coding method is utilized, but an example of what code to detect the dependent NI-DAQmx library using the
find_library() function could look like is commented out. More information on the
find_ functions can be found in the
CMake command documentation.
- Once the above edits have been completed, the project can be cross-compiled and deployed to your Linux RT Target. The procedure from this point on is identical to the process outlined in part 4 of the Linux RT cross-compiling guide. Return to this guide, open Part 4, and follow the steps starting at the Building subsection on page 4 with your ANSI C NI-DAQmx example project to build, deploy, and run your cross-compiled NI-DAQmx code.