Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Compiling the CIN Source Code

LabVIEW 8.5 Help
August 2007

NI Part Number:
371361D-01

»View Product Info

You must compile the source code for the CIN as a LabVIEW subroutine (.lsb) file. After you compile your C/C++ code in one of the compilers that LabVIEW supports, you use a LabVIEW utility that puts the object code into the .lsb format.

Note  You must use the cdecl calling convention to compile C code for the CIN. The calling convention defines how data is passed to a function and how clean up occurs after the function call is complete.

Because the compiling process is often complex, LabVIEW includes utilities that simplify the process. These utilities take a simple specification for a CIN and create object code you can load into LabVIEW. The specific utility you use depends on the platform and compiler you use. Refer to the following sections for more information about compiling on your platform.

Note  The LabVIEW Base Package can use existing .lsb files but cannot create new .lsb files. You can create .lsb files in the LabVIEW Full and Professional Development Systems.

Microsoft Windows

To build CINs for LabVIEW on Windows, use the Microsoft Visual C++ or Symantec C compilers.


Visual C++ Command Line

This section describes using command line tools on Windows to build CINs.

  1. Add a CINTOOLSDIR definition to your list of user environment variables. You can edit this list with the System control panel accessory. For example, if you installed LabVIEW on Windows in c:\Program Files\National Instruments\LabVIEW x.x, the CIN tools directory should be c:\Program Files\National Instruments\LabVIEW x.x\cintools, where x.x is the LabVIEW version number. In this instance, you would add the following line to the user environment variables using the System control panel:

    CINTOOLSDIR = c:\Program Files\National Instruments\LabVIEW x.x\cintools
  2. Build a .lvm file (LabVIEW Makefile) for your CIN. You must specify the following items:
    • name is the name of your CIN, for example, mult.
    • type is CIN.
    • !include $(CINTOOLSDIR)\ntlvsb.mak
    To define additional include paths for a CIN you must add a CINCLUDES line to the .lvm file, as shown in the following example code:

    CINCLUDE = -Ipathnames

    You must include the -I argument on the line. pathnames is the directory where you look for other includes.

    If your CIN uses extra object files, you can specify the objFiles option. You do not need to specify the codeDir parameter because the code for the CIN must be in the same directory as the makefile. You do not need to specify the wcDir parameter because the CIN tools can determine the location of the compiler.

    You can compile the CIN code using the following command, where mult is the makefile name:

    nmake /f mult.lvm

    If you want to use standard C or Windows libraries, define the symbol cinLibraries. For example, to use standard C functions in the previous example, you could use the following .lvm file:

    name = mult

    type = CIN

    cinLibraries=libc.lib

    !include $(CINTOOLSDIR)\ntlvsb.mak

    To include multiple libraries, separate the list of library names with spaces.

Symantec C

Building CINs using Symantec C is similar to building CINs for Visual C++ Command Line. However, you should use smake instead of nmake on your .lvm file.

Mac OS

LabVIEW includes a template to help you build CINs using the Xcode development environment from Apple Computer, Inc. It is possible to build a CIN with Metrowerks CodeWarrior, but LabVIEW does not provide a template or instructions.

To set up a CIN project on Mac OS, you must first install the CIN template into Xcode.

Install the CIN template into Xcode by copying the LabVIEW Templates folder from the labview\cintools\Xcode Files directory into the \Library\Application Support\Apple\Developer Tools\Project Templates directory.

Complete the following steps to create a new CIN project using Xcode.

  1. In Xcode, select File»New Project.
  2. Select LabVIEW Templates»CIN 8.0 and specify a name and location for the project.
  3. Add source code by selecting Project»Add Files.
  4. Build the .lsb file. LabVIEW places the .lsb file next to the project file.

The ReadMe (Xcode).rtf file located in the labview\cintools\Xcode Files directory also includes information about how to install the CIN template into Xcode and how to create a new CIN project.

Linux

The only supported compiler for Linux is gcc.

gcc Compiler

Create a makefile using the shell script lvmkmf (LabVIEW Make Makefile), which creates a makefile for a given CIN. Use the standard make command to make the CIN code. In addition to compiling the CIN, the makefile puts the code in a form LabVIEW can use.

The format for the lvmkmf command is shown in the following example code, with optional parameters listed in brackets.

lvmkmf [-o Makefile] LVSBName

LVSBName is the name of the CIN you want to build. If LVSBName is foo, the compiler assumes the source is foo.c and names the output file foo.lsb.

-o is the name of the makefile lvmkmf creates. If you do not specify this argument, the makefile name default is Makefile.

The created makefile will be similar to the following example code.

In the following example code, add the LabVIEW version number, for example lv70, to the end of lv.

#
# This Makefile was generated automatically by lvmkmf.
#

CC=gcc
LD=gcc
LDFLAGS=-shared
XFLAGS=-fPIC
CINDIR=/usr/local/lv/cintools
CFLAGS=-I$ $
CINLIB=$/libcin.a
MAKEGLUE=$/makeglueSVR4.awk
AS=as

The makefile produced assumes the cin.o, libcin.a, and lvsbutil files are in certain locations. If these assumptions are incorrect, you can edit the makefile to correct the pathnames.

After you compile the source code for the CIN, load the CIN object code.


Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit