# Using the NAG C Library Mark 23 Windows DLLs

The information on this page is applicable to Mark 23 of the NAG C Library DLLs (shipped with CLW3223DAL) unless otherwise stated.

## Accessing the Library from the Command Line

In the following, driver.c represents the name of your application program and install dir is the folder where the NAG C Library DLLs product is installed.

• Microsoft Visual C++
  cl /MD /I"install dir\include" driver.c
"install dir\lib\CLW3223DA_nag.lib"

(on one continuous line).

The "/MD" option should be used to specify linking with MSVCRT.LIB.

Alternatively, if you wish to link to the version of the NAG C Library that uses the Intel® Math Kernel Library 10.3 for Windows (MKL) which is included in this product, you should compile your program in the following manner:

  cl /MD /I"install dir\include" driver.c
"install dir\lib\CLW3223DA_mkl.lib"



If the folder containing the import libraries has been added to the LIB environment variable and the include folder has been added to the INCLUDE environment variable, these commands may be simplified to

  cl /MD driver.c CLW3223DA_nag.lib


and

  cl /MD driver.c CLW3223DA_mkl.lib


respectively.

• Intel C++
  icl /MD /I"install dir\include" driver.c
"install dir\lib\CLW3223DA_nag.lib"

or, if the LIB and INCLUDE environment variables have set appropriately,
  icl /MD driver.c CLW3223DA_nag.lib



Substitute CLW3223DA_mkl.lib to use MKL.

• Borland C++

• gcc

To compile with gcc in a Windows command prompt window:

  gcc -I "install dir\include" driver.c
"install dir\lib\CLW3223DA_nag.lib" -o driver.exe


To compile with gcc in a Cygwin xterm window:
  gcc -I "install dir/include" driver.c
"install dir/lib/CLW3223DA_nag.lib" -o driver.exe

or
  gcc -I install\ dir/include driver.c
install\ dir/lib/CLW3223DA_nag.lib -o driver.exe


With older versions of gcc, the -mno-cygwin option may also be required.  This option removes dependence on cygwin1.dll, using the MinGW version of gcc instead (which is shipped as part of Cygwin). Because both the NAG C Library DLLs and the executables produced by the MinGW gcc compiler use the Microsoft runtime libraries, I/O issues are less likely to occur.  This option is not available (or necessary) with newer versions of gcc (e.g. gcc version 4.3.4).

Substitute CLW3223DA_mkl.lib to use MKL.

## Accessing the Library from Other Environments

The NAG C Library DLLs can also be accessed from many GUI environments. The web pages in the list below contain links to sample projects for Microsoft Visual C++, Microsoft Visual Basic 6 and Microsoft Visual Basic .NET, worksheets for Microsoft Excel and some examples showing how to access the NAG C Library from C# and Java applications.

To facilitate calling the NAG C Library DLLs from Visual Basic, header files have been produced, providing declare statements for each function, type / structure definitions, constants, enumerated types and skeleton call-back functions (where appropriate). There are four sets of headers:

## General Advice on Accessing the Library

When running any program linked with the NAG C Library the appropriate DLLs need to be accessible.

The .\bin subfolder of the library folder must be included in your PATH to run applications.

The .\MKL_ia32_10.3\bin subfolder of the library folder must be included in your PATH to run applications linked with MKL. This should appear later in your PATH than the .\bin folder containing the NAG DLLs.

The installation script may have attempted to do this for you, but in some cases manual intervention may be required. On most systems this may be effected using the Environment Variables button on the Control Panel | System | Advanced tab (Advanced System Settings on Windows Vista / Windows 7).

To include functions from the Library in projects developed under an integrated development environment (e.g. Microsoft Developer Studio), the project environment must be set to search for include (.h) files in the .\include subfolder of the library folder. Library files must be searched for under the .\lib subfolder of the library folder. In Developer Studio open the Tools | Options dialog box, select the Projects (or Projects and Solutions) | VC++ Directories section and enter the appropriate setting for each type of folder. In this DLL implementation, for convenience, the MKL symbols are exported directly from the NAG import library CLW3223DA_mkl.lib, so it is not necessary to specify the MKL import libraries subfolder (.\MKL_ia32_10.3\lib) as well.

If your machine has more than one processor and you are using Intel MKL, then it is recommended that you set the environment variable OMP_NUM_THREADS to the number of available processors, e.g.

  set OMP_NUM_THREADS=2


This will enable the Intel MKL BLAS to make use of the extra processor(s) and will thus speed up the computation of many of the NAG library routines. On most systems setting this environment variable may be effected using the Environment Variables button on the Control Panel | System | Advanced tab (Advanced System Settings on Windows Vista / Windows 7).

Normally you are advised to use NAG_ALLOC to allocate memory and NAG_FREE to deallocate memory, however in mixed language programming, these C preprocessor macros are not available. Instead you may call the x04bjc and x04bdc functions directly to allocate and deallocate memory.

The function x04bjc is the NAG memory allocator in this implementation.

  Pointer NAG_CALL x04bjc(size_t size);


The function x04bdc is the NAG memory deallocator.

  void NAG_CALL x04bdc(Pointer *ptr);



Note: Within a number of NAG C Library functions, memory is allocated internally and returned to the calling function. This allocated memory contains information that is potentially useful to the user. Consequently freeing this memory has been left to user discretion. However, in the context of DLLs such internally allocated memory cannot be freed externally.

For an example of the use of x04bdc, please refer to the g05eac example program.

Note that the NAG C Library DLLs supplied with CLW3223DAL use the __stdcall calling convention for function calls.