Tutorial on using Visual Studio 2012 with the NAG C Library
Start
64 Bit Applications
Calling NAG Example Programs
Creating Property Sheets
Applying Property Sheets
Create a New Project by selecting New Project from the FILE menu.
From the New Project Dialog select Templates -> Visual C++ -> General -> Empty Project and give the project a name.
Right click on Source Files under the Solution Explorer and Add a New Item.
Choose a C++ File (.cpp) and name it main.cpp.
Write a simple helloworld program in your main.cpp file.
Pressing F5 will run the program, but the output window will close instantly, so you will be unable to see the output. We can change this in the Project Properties.
Right click on Project Name under Solution Explorer and select Properties. Note you want the Project Properties here not the Solution Properties.
You will now see the Project Properties Page.
Under Configuration Properties -> Linker -> System, change the value of Subsystem to Console (/SUBSYSTEM:CONSOLE). This will allow us to run the program and see output. Note - You must press Ctrl + F5 to run, rather than just F5.
Save the changes by clicking OK and run the program by pressing Ctrl + F5. The program should now stay open until a key is pressed.
Now we will adjust the properties to be able to use the NAG C Library. Open the Project Properties once more.
First we need to add the location of NAG C Library header files under Configuration Properties -> VC++ Directories -> Include Directories. In this example we will be using the NAG C Library clw3223dal in which the default location of the headers will be found in C:\Program Files (x86)\NAG\CL23\clw3223dal\include on a 64 Bit Windows machine.
Second we need to add the location of the NAG C Library under Configuration Properties -> Linker -> Input -> Additional Dependencies. Again on a 64 Bit Windows machine the default location is C:\Program Files (x86)\NAG\CL23\clw3223dal\lib\CLW3223DA_nag.lib. Click OK
Include nag.h and naga00.h to your helloworld program and add a call to a00aac(). Run using the Local Windows Debug button again. This time you should see the About NAG C Library dialog.
That's it! You will need to add the include directory and the library path using the Project Properties Page for every project that you want to use the NAG C Library with. Alternatively this can be done using a Property Sheet. Instructions for doing can be found in the Creating A Property Sheet section.
Using the 64 Bit NAG C Library
First we need to change the platform to 64 Bit. Select the right hand drop-down on the upper Task Bar (currently displaying Win32) and select Configuration Manager.
Select the drop-down under Platform that corresponds to your project, and click New.
Under New Platform, x64 should be selected. Under Copy settings from: choose Empty and click OK. Close the Configuration Manager.
We now need to edit the Project Properties as we did previously to use the 64 Bit Library. Right click on the Project Name under Solution Explorer.
Add the location of NAG C Library header files under Configuration Properties -> VC++ Directories -> Include Directories. The default location of the headers for the cl6i23dal library will be found in C:\Program Files\NAG\CL23\clw6i23dal\include on a 64 Bit Windows machine.
Next add the location of the NAG C Library under Configuration Properties -> Linker -> Input -> Additional Dependencies. Again on a 64 Bit Windows machine the default location is C:\Program Files\NAG\CL23\clw6i23dal\lib\CLW6I23DA_nag.lib. Apply the changes and click OK.
We can now run the program with Ctrl + F5 and we will be shown the NAG C Library Dialog.
Attempting to run the program with debugging (By pressing F5) will generate the information message shown below telling us debugging information cannot be found. To enable debugging for 64 Bit applications, we need to return to the Project Properties.
Under Configuration Properties -> C/C++ -> General, change the value of Debug Information Format on the right hand side to Program Database For Edit And Continue (/ZI).
Now select Optimization on the left, and change Optimization on the right to Disabled (/Od)
Under Configuration Properties -> Linker -> Debugging, change the value of Generate Debug Info to Yes. Apply the changes and click OK.
You will now be able to debug programs in 64 Bit mode.
Calling NAG Example Programs
Each routine in the NAG C library has an associated example program. These examples are distributed along with the NAG C Library. For the purpose of this tutorial, we will be calling the example program for the function g01eac. In Windows Explorer, navigate to the default installation location for clw3223dal. On a 64 Bit Windows machine this is "C:\Program Files (x86)\NAG\CL23\clw3223dal". Select the folder named examples.
Inside the examples folder you will see the source, data and results folder. The source folder contains the C examples code, the data folder contains the input data files for each example and the results folders contains the expected output or each routine. Select the source folder, and navigate to g01eace.c. Open this file in any text editor (such as Notepad) and copy the code.
Paste the code into the main.cpp file of a new project in Visual Studio.
We must now get the program to read from the associated data file. Return to Visual Studio and open the Project Properties on the right hand side.
Under Configuration Properties -> Debugging, edit Command Arguments.
You will need to use the redirection operator < followed by the path to the file enclosed in double quotes ( " " ). The data file you need is in the main NAG folder, in examples\data. An example of the path is shown below.
Apply the changes and click OK. The program will now run when we press Local Windows Debugger, taking its data from the file we specified. The output should match that given in the results file, which can be found in the examples\results folder in the main NAG directory
Creating a Property Sheet
Property Sheets are useful when using the same properties over multiple projects
From View -> Other Windows bring up the Property Manager explorer.
You should now see the Property Manager window.
From the Property Manager click Add New Project Property Sheet.
Give the sheet and name and click Add. You will now see a Property Page.
Set up the Include directory and Library Path as you did before and click okay.
Save the changes that you just made to the Property Sheet.
The Property Sheet will either be saved to C:\Users\{USER}\AppData\Local\Microsoft\MSBuild\v4.0 (AppData is a hidden folder) or to C:\Users\{USER}\My Documents\Visual Studio 2012\Projects\{PROJECT NAME} by default. You might want to store the Property Sheet somewhere more accessible.
Applying the Property Sheet to a Project
Create a New Project and make sure the Property Manager window is visable. From the Property Manager click Add Existing Property Sheet and navigate to the Property Sheet created earlier.
You will now see the Property Sheet applied.
Add a main.cpp with a call to a NAG C Library function i.e. a00aac. Compile and run the project with Local Windows Debug and you should see the implementations dialogs if successful.