Compiling newmat under Microsoft Visual C++

VC++5 or 6

Here are my instructions for compiling a program with newmat under VC++5 or 6 to work in console mode (i.e. run in an MS-DOS window).

VC++ 7 (i.e. the version that comes with Visual Studio .NET) is a little different and there are some preliminary notes below.

I assume you are familiar with the idea of writing and running a program in C++, in the old fashioned way, and just need advice how to compile and run such a program using Visual C++. Otherwise get a book on C++.

I am using VC++'s graphical interface.

You write a main program to carry out your analyses and calling the newmat functions you need. My file example.cpp is an example of such a main program.

Follow the following steps for setting up your project.

For a start use one of my examples (eg example.cpp), use console mode and don't try to generate a library version of newmat.

I say again: unless you are very familiar with Visual Studio for a start use one of my examples (eg example.cpp), use console mode and don't try to generate a library version of newmat. Don't try to use the library file that you can generate with my make file.

  1. Create a directory such as VC where you want to keep all your visual C++ projects. I suppose this on the f: disk.
  2. Make a subdirectory newmat10
  3. Copy all my newmat files to that directory together with your main program. I am going to compile my example program which is included with newmat10
  4. Start VC++
  5. Select file - new - workspaces
  6. In location select f:\vc (if f is the disk you are using); in workspace name type newmat10; click OK
  7. Select file - new - projects
  8. Under project name enter example (or the name of your project); click the button add to current workspace; click the line Win32 console application; the box labelled Platforms should have Win32 checked; click OK It will ask you what kind of project - select an empty project - then click finish.
  9. Select menu project - add to project - files
  10. Hold down the control key and click all the files needed in the project (this is all the .cpp and .h files if you are compiling my test program except the tmt*.* files, nl_ex.cpp, sl_ex.cpp, garch.cpp, text_exc.cpp, nm_ex1.cpp, nm_ex2.cpp); click OK
  11. Go to project - select active project and select example or your project name
  12. Go to build - select active configuration and select debug. Click OK
  13. In the left hand window click the + beside example to get the list of files. Double click include.h. (omit steps 13 and 14 in the latest version of newmat).
  14. Edit my file include.h to enable the compiler supported exceptions and to use the compiler's Boolean function
  15. Go to build - build example.exe. This should initiate the compile
  16. Click the icon ! or !execute example.exe in the build menu. This will run the program. Or you can run the program from an MSDOS window; see below for where the .exe file is hidden.

 

Notes

If you are making the runtime version rather than the debug version in VC++5 be sure to turn off optimisation - go to project - settings - C/C++ and select disable (debug) - not required for VC++6.

The .exe file is in a subdirectory called debug for the debugging version and in a subdirectory called release for the release version.

You can select an option to create a static library file at step 8 (call the project newmat10 and just include the newmat files) and then add the library file to another project, instead of all the newmat files. You do have to be careful to make sure you add in the debug version of the library file if you are debugging and the run version of you are compiling the run version. You can add both libraries. Then right-click newmat10.lib in the workspace window and choose settings - General in the pop-up window. Then set Exclude file from build to exclude the release version of newmat10.lib from the debug version and vice versa. You can see which version of newmat10.lib you have selected by selecting the Custom Build tab.

 

VC++ 7 preliminary notes

Workspaces are now called solutions. Follow the steps for VC++ 5 and 6 up to step 7.

At step 8 select Visual C++ projects, enter the name of your project (e.g. example), click add to current solution, and select win32 project from the templates and click OK. This should bring up the Win 32 application wizard. Click the heading applications. Then select console application and empty project. Click finish.

At step 9 select the heading add existing item in the project menu. You'll have to go up a directory to get the files.

Skip step 11 and use the configuration manager under the build menu to select whether you want the debug or release version. (When you have several projects you select the one to be compiled by clicking it in the solution manager window).

You can change the options for the project by going to properties on the project menu. Make sure the precompiled headings option is set to not using precompiled headers.

Go to step 15 to do the compile; you will get some warnings but there should be no errors. If you get masses of errors about precompiled headers go back to the previous step and turn off the precompiled header option.

You can run the project from the debug menu - use start without debugging or you can search out the .exe file. I haven't discovered how to set which of several projects actually gets run.