Contents

Setting up a Build Environment on Windows Systems

Setting up the build environment involves specifying the header files and libraries that you need to create an adaptor. For those familiar with their IDE environment, see the following sections for lists of these required include files and libraries. This section also describes how to create an environment variable that you can use to specify the MATLAB® installation folder. The header file and library paths use this environment variable. For detailed instructions on setting up your build environment in the Microsoft® Visual C++® development environment, see Creating an Adaptor Project Using Microsoft Visual C++.

Required Header Files and Libraries

The following table lists the locations of the header files and libraries that you need to build an adaptor.

    Note   You must also specify the location of the header files and libraries required by your device. Read your device's SDK documentation to get this information.

Header File and Libraries

Location

Adaptor kit header files

$(MATLAB)\toolbox\imaq\imaqadaptors\kit\include[a]

Image Acquisition Toolbox™ engine library

$(MATLAB)\toolbox\imaq\imaqadaptors\kit\lib\<ARCH>\release\imaqmex.lib

[a] MATLAB is an environment variable that contains the name of your MATLAB installation folder.

Using Environment Variables

To create an environment variable on your Windows® 7 system that specifies your MATLAB installation folder, follow this procedure:

  1. Open the System Properties dialog box. One way to do this on a Windows 7 system is to click the Start menu and then right-click the Computer option and select Properties.

  2. In the System Control Panel, click the Advanced system settings option.

  3. On the Advanced tab, click the Environment Variables button.

  4. In the Environment Variables dialog box, in the User variables section, click New to create an environment variable.

  5. In the New User Variable dialog box, assign the name MATLAB to the variable and set the value of the variable to your MATLAB installation folder path. Click OK.

  6. Click OK in the Environment Variables dialog box.

  7. Click OK in the System Properties dialog box.

      Note   If Microsoft Visual C++ is running when you create this variable, you must restart it.

Creating an Adaptor Project Using Microsoft Visual C++

As the first step toward building an adaptor, open Microsoft Visual C++ and create a new project.

  1. Set up any required environment variables—see Using Environment Variables.

  2. Start Microsoft Visual C++ 2010.

  3. On the Start Page, click New Project.... Visual Studio opens the New Project dialog box, shown in the following figure. You can also open this dialog box from the File > New > Project menu.

  4. In the New Project dialog box:

    • Expand Visual C++, under Installed Templates, if needed, and select Win32.

    • Select Win32 Project.

    • Enter the name you want to assign to the project in the Name field and specify where you want to locate the project in the Location field.

      You can give your adaptor project any name. A convention used by the toolbox is to name adaptors as follows:

      vendor_name + imaq
      

      where you replace the string vendor_name with something appropriate to your project. For example, this documentation specifies the project name MyDeviceImaq. Microsoft Visual C++ uses the project name as the default adaptor DLL name. To specify a different name for the adaptor DLL, open the project property pages (Project > Properties), open Linker, click General, and edit the Output File field.

    • Click OK. Visual C++ opens the Win32 Application Wizard.

  5. In the Win32 Application Wizard, click Application Settings.

  6. On the Application Settings page, select DLL from the list of application types and select Empty project from the Additional options section. Click Finish to create the project.

After you create the project, close the Start Page . Visual C++ displays the project in its Solution Explorer, with separate folders for source files, header files, and other project resources, as shown in the following figure.

Recompiling with New Versions of the Image Acquisition Toolbox Software

After you have created an adaptor, you generally only need to recompile it for use with new major versions of the Image Acquisition Toolbox software. Adaptor writers should recompile when a major update is released, such as Image Acquisition Toolbox Version 4.0. If your adaptor works in one version but not in the new version of the toolbox, try recompiling and relinking to see if that resolves the issue.

Minor updates of the toolbox generally do not include changes to the adaptor kit, so adaptor writers generally will not need to recompile their adaptors.

Adding the Adaptor Kit Project to Your Solution

When you create a project, Microsoft Visual C++ automatically creates a solution that contains your project. As a convenience, while you are developing your adaptor, you might want to add the adaptor kit project to your solution to make it easier to refer to adaptor kit files. Adding the adaptor kit project to your solution does not affect the compilation or linkage of your adaptor DLL.

To add the adaptor kit project to your solution, go to the File > Add > Existing Project menu. In the Add Existing Project dialog box, open the following project file,

matlabroot\toolbox\imaq\imaqadaptors\kit\imaqadaptorkit.vcxproj

where matlabroot represents your MATLAB installation folder.

Specifying Header File Locations

Before you can compile your adaptor, you must specify the locations of the header files required by the adaptor kit and by your device's SDK. For a list of the header files required by the adaptor kit, see Setting up a Build Environment on Windows Systems. The following section describes how to specify these header file locations in the Microsoft Visual C++ 2010 environment.

Specifying Header Files in Microsoft Visual C++ 2010

To specify the locations of the adaptor kit header files in Microsoft Visual C++ 2010, follow these instructions:

  1. Open the Property Pages dialog box: Projects > Properties.

  2. Change the Configuration setting (at the top of the dialog box) to All Configurations.

  3. Expand Configuration Properties and select VC++ Directories.

    Then select Include Directories and choose Edit from the menu associated with that row.

  4. Add the locations of adaptor kit header files and the header files required by your device's SDK to the list of folders displayed, each on a separate line.

    $(MATLAB)\toolbox\imaq\imaqadaptors\kit\include
    

    In this example, $(MATLAB) dereferences the environment variable MATLAB, which is set to the name of your installation folder. (See Using Environment Variables for more information.)

  5. After specifying the header file folders, click OK.

Specifying Libraries and Library Paths

Before you can create your adaptor DLL, you must specify the libraries required by the adaptor kit and by your device's SDK. For a list of required libraries, see Setting up a Build Environment on Windows Systems. The following sections describes how to specify these libraries and library paths in Microsoft Visual C++.

Specifying Library Locations in Microsoft Visual C++ 2010

  1. Open the Property Pages dialog box (if it is not already open): Projects > Properties.

  2. Change the Configuration setting (at the top of the dialog box) to All Configurations.

  3. Expand Configuration Properties and then expand Linker. Select General and, on this page, select Additional Library Directories and click Edit from the menu associated with that row.

  4. Add the locations of adaptor kit libraries and the libraries required by your device's SDK in the Additional Library Directories field. Use a semicolon to separate the folders.

    This example adds this line to the field:

    $(MATLAB)\toolbox\imaq\imaqadaptors\kit\lib\<ARCH>\release
    

    In the example,$(MATLAB) dereferences the environment variable MATLAB, which is set to the name of your installation folder — see Using Environment Variables. You must replace <ARCH> with the name of an architecture-specific folder, such as, win32 or win64.

Specifying Library Names in Microsoft Visual C++ 2010

To specify the library names, follow this procedure.

  1. Open the Property Pages dialog box (if you do not already have it open): Projects > Properties.

  2. Change the Configuration setting (at the top of the dialog box) to All Configurations.

  3. In the Property Pages dialog box for your project, expand Configuration Properties and then expand Linker. Select the Input category and, on this page, select Additional Dependencies and click Edit.

  4. Specify the names of the adaptor kit libraries and the names of the libraries required by your device's SDK. Use spaces to separate the names of the libraries. The following shows the adaptor kit libraries.

    imaqmex.lib 
    

  5. Click OK.

Configuring Other Project Parameters

In addition to specifying the header files and libraries, an adaptor project requires these additional settings. If you do not set these parameters, your adaptor might encounter run-time problems.

  1. Add an empty source file to your project. To set the values of these additional properties, your project must contain files. To create a source file, follow this procedure:

    1. Select File > New > File.

    2. In the New File dialog box, select Visual C++.

    3. Select C++ File (.cpp) and then click Open.

    4. Add the new source file to your project. From the File menu, select Move Source1.cpp into and select the name of your project. Accept the default file name for now; you can always change it later.

  2. Open the Property Pages for your project by right-clicking on your project in the Solution Explorer and choosing Properties, or by selecting Properties from the Project menu.

  3. In the Property Pages dialog box, open C/C++ and select Code Generation. On the Code Generation page, set the following values.

    Field

    Setting

    Enable C++ Exceptions

    Yes with Extern C functions (/EHs)

    Runtime library

    Multi-threaded DLL (/MD)

    Buffer Security Check

    No (/GS-)

  4. In the Property Pages dialog box, under C/C++, select Language. On the Language page, set the Enable Run-time Type Information field to Yes (/GR).

  5. In the Property Pages dialog box, under C/C++, select Command Line and specify the following compiler flag. Click OK to close the Property Pages dialog box.

    /EHs
    

Was this topic helpful?