This tutorial shows you step by step how to run one of the NAG example programs on Visual Studio. It is easiest at first to work with the example programs and adapt them to your needs.
First, open up an new Win32 console project. Remember to change the build directories, you have to do this every time you open a new project (see Getting Started).
Now we want to copy the NAG example source code into the *.cpp file in Visual Studio. The example programs are found in:
Find the file
d02race.c, copy and paste it onto your desktop.
Next, delete the main function from the *.cpp file in Visual Studio, we do not want two main functions in the program. Make sure you leave the
Now open the document
d02race.c with wordpad, select all, copy and paste underneath the
Next we need to add a pause command so that the terminal does not disappear before we can see the results. Search with the document for the main function, and find the line with
return exit_status;. Put in an extra line with the code
system ("pause"); above that line.
Now we need to add the extra include directories and dependencies needed to compile against the NAG library. Open
Project > Properties and go to
C++ > Additional Include Directories. You need to add the directory
by either manually entering the text or by searching for it using the button with dots on.
Now for the dependencies, go to
Project > Properties ,
Linker > Input > Additional Dependencies and enter
You will need to do this by typing it in, or copying and pasting.
Now we are ready to run the code! Press on start debugging. If you are lucky you will see:
If you are not so lucky you may see
This means there is a problem with the licence file on the machine. To get it to work select
Start Menu > Site Licenced Applications > Mathematical Applications > NAG Library > NAG C Library Command Line
Once ZENworks has done its job and the command line is loaded try to run the program again. If it still doesn't work, open
Start Menu > Site Licenced Applications > Mathematical Applications > NAG Library > NAG Fortran Library Command Line and try again.
Making a new class
Optimising your programs
Mathematics and software