来自:Using External Code in LabVIEW.pdf (NI公司)
Microsoft Windows
To build CINs for LabVIEW for Windows, use the Microsoft Visual C++
or Symantec C compilers.
Visual C++ IDE
Complete the following steps to build CINs using the Visual C++
integrated development environment (IDE).
1. Select File»New to create a new DLL project.
2. Select Win32 Dynamic-Link Library as the project type. You can
name your project whatever you want.
3. Select An empty DLL project when prompted to choose the type of
DLL that you want to create and click Finish.
4. Select Project»Add To Project»Files and navigate to your .c file.
Select your .c file and click the Open button to add the .c file to the
project.
5. Select Project»Add To Project»Files to add CIN objects and libraries
to the project. Select cin.obj, labview.lib, lvsb.lib, and
lvsbmain.def from the Cintools subdirectory. You need these files
to build a CIN.
6. Select Project»Settings and change Settings For to All
Configurations. Click the C/C++ tab and set the category to
Preprocessor. Add the path to your Cintools directory in the
Additional include directories field.
7. Select Project»Settings and change Settings For to All
Configurations. Click the C/C++ tab and set the category to Code
Generation. Select the Struct member alignment tab and select 1
byte.
8. Choose a run-time library. Select Project»Settings and change
Settings for to All Configurations. Select the C/C++ tab and set the
category to Code Generation. Select Multithreaded DLL in the Use
run-time library control.
Chapter 3 CINs
Using External Code in LabVIEW 3-16 ni.com
9. Make a custom build command to run lvsbutil. Select
Project»Settings and change Settings for to All Configurations.
Select the Custom Build tab and change the Commands field as
follows, with the code all on a single line:
<your path to cintools>/lvsbutil “$(TargetName)” -d
"$(WkspDir)/$(OutDir)"
Change the Output fields to $(OutDir)$(TargetName).lsb.
10. (For Visual C++.NET compiler only) Add
<CINTOOLSDIR>/lvsbmain.def to the Linker»Input»Module
Definition File field.
11. Click the File View tab in the Work Space window.
12. Open your .c file and replace /* Insert code here */ with your
code.
13. Select Build»Build projectName.dll, where projectName is the name
of your project.
Visual C++ Command Line
This section describes using command line tools in Windows to build
CINs.
1. Add a CINTOOLSDIR definition to your list of user environment
variables.
(Windows 2000/NT/XP) You can edit this list with the System control
panel accessory. For example, if you installed LabVIEW for 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
(Windows Me/98) Modify your AUTOEXEC.BAT to set CINTOOLSDIR to
the correct value.
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
Chapter 3 CINs
© National Instruments Corporation 3-17 Using External Code in LabVIEW
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.