This document is part of The Definitive Guide: Programming NI VxWorks Real-Time Controllers in C/C++. Here, we detail the use of a gcc redistributable to program these controllers. We assume you have followed the previous guide and have downloaded the appropriate gcc distribution for your target and version of VxWorks.
A note on operating system compatibility: gcc compiler 3.3.2 with VxWorks 6.1 distribution uses shell scripting techniques that are not compatible with Windows Vista or Windows 7. Upgrade to LabVIEW Real-Time 2009 or 2010 and use gcc compiler 3.4.4 with VxWorks 6.3 distribution, or use Windows XP.
Extract the gcc redistributable to your hard drive. We suggest using paths without spaces or special characters, i.e. c:\gccdist . You will see the following directory structure:
Figure 2.1a: gcc redistributable extracted.
The docs folder contains documents for using the gcc compiler. The supplemental folder contains example projects and tools to setup environment variables. The WindRiver folder contains the gcc distribution and VxWorks 6.x redistributable.
gcc is a command-line tool, and projects are compiled with GNU Make. Make requires that tools be available in the command-line path; in addition, VxWorks references a license file that must be stored in an environment variable. These variables are set for each command-line session using a batch script. Before this script is executed the first time, confirm that the script is correctly pointing to the folder where you extracted the gcc distribution. Edit the file supplemental/setup-gcc.bat and verify that the installation location is correct:
Figure 2.2a: Confirming the correct location of the gcc distribution in the setup batch file.
This script must be executed for each command-line shell, since environment variables are not stored across sessions. Alternately, you may configure machine-level environment variables through the Windows operating system. See the tutorial, Environment Variables in Windows XP for instructions. View the file supplemental\setup-gcc.bat to see which environment variables are set for your distribution.
Navigate to the supplemental folder and execute setup-gcc.bat. You may skip this step if you have configured environment variables at you user-account level.
Figure 3.1a: Configuring the command-line environment for compilation.
Note that the environment variables are stored for this session of the command-line only; closing the command-line window and opening another requires this step be repeated.
We compile the example project Fib, which exports two library functions for generating Fiboncci numbers. The source for fib.c is shown below:
Compile the code by using the provided makefile. Navigate to supplemental\examples\fib\c code\ and type make :
Figure 3.2a: Output of the make command in the Fib project.
The file PPC603GNU\fib.out is the binary library that may be executed on the target. Refer to the top-level document, The Definitive Guide: Programming NI VxWorks Real-Time Controllers in C/C++ for instructions on how to upload your binary to the target and execute your code.
The provided template makefile should be customized for your project, specifically the .out file generated needs to be associated with the top-level source file for your library. See the comments in the makefile for more detail. In short, you should change the first line of the makefile to match the name of the top-level .c or .cpp file:
# Specific to this library; expects NAME.c or NAME.cpp, and produces NAME.out
LIBRARY = myLibrary
Instructions for disabling the CPU Exception Handler are found in the top-level guide, The Definitive Guide: Programming NI VxWorks Real-Time Controllers in C/C++.
The VxWorks Kernel Shell can print debug statements compiled into the library, and can set breakpoints at functional scope. Consult VxWorks documentation for more details. Visit the references in the top-level document for a walkthrough of debugging using the VxWorks Kernel Shell.
Yes, the makefiles in other NI links did not work, but this one did the job. Thanks a lot..
Yes, my bad - in the batch file, rename the directory "supp" to "supplemental" and it should work.
I doubt if its because of different directory folder. I tried now, it did not work. Apparently the makefiles themselves were different in the download files given in NI links like http://www.ni.com/white-paper/5694/en/ and the one here. Earlier, when I had tried those downloaded files in my Windows 8 OS, the execution had stopped abruptly, but may be once in, say 15 - 20 times, it would successfully give results.