Building under Microsoft Visual Studio
If you are building GPSTk under the Cygwin
environment, then use the jam portion of BuildingGPSTkUnderUnix
The GPSTk is not supported under Microsoft Visual C++ Version 6.0, or earlier, because templates in classes are not supported. Currently there is support for Microsoft Visual Studio C++ .NET 2003 (Version 7) and the Microsoft Visual C++ Express 2005 (Version 8, freely available here
). Makefiles for Microsoft Visual C++ are not provided in the toolkit, however note that the Visual C++ IDE is able to import existing code, and so makefiles could probably be generated via the IDE. The GPSTk supports using jam and the command line tools to build.
Here are the 5 steps (followed by 6 notes) needed to build under Microsoft Visual C++.
- Ensure that prerequisites such as jam have been installed.
- Ensure that there is a system regular expression library installed. See InstallingRegexSupportForVisualCPP.
- Jam must be told where to find the command line tools (compiler and linker). It does this through the environment variable MSVCNT; see step 3. Problems have arisen here when the installation directory has whitespace in it. It has worked correctly with Visual Studio Express 2005 with white space. You could also try quoting the string with whitespace. Another option is to install the MS VC++ tools into a directory with no whitespace; for example C:\MSVC2003. Some have said that jam can be made to work using the "DOS 8.3" version of the path, but this has not been tested.
- Open a command window in which to build the toolkit. The MS VC++ tools require that appropriate paths be defined before the command line tools will work. MS provides a batch file that sets the PATH and other environment variables; it is called VSVARS32.bat and is found in the directory C:\MSVC2003\Common7\Tools. Don't confuse this with VCVARS32.bat. After you have run VSVARS32, you should be able to type
cl at the command prompt and get the MS compiler.
- Jam also relies on environment variables, two of them, in order to run. The jam executable looks at the variable MSVCNT to find the path of the command line tools. Also, the Jamrules file has been set up to look at the variable MSCVER to determine which set of compiler and linker options is to be used. Thus for the 2003 compiler:
or if you are using the 2005 compiler instead:
Of course you may have other install directories; this example uses C:\MSVC2003 for the 2003 tools and C:\MSVC2005 for the 2005 tools. Note the different subdirectories '\VC7' and '\VC'; this is an MS thing, these are the directories where the \bin, \lib, and \include directories are found. (The values 1300 and 1400 were chosen because all MS compilers define the macro _MSC_VER as a float number of the form 'MMmm.mm' where MM is the major version, and mm.mm is the minor version number; in MS VC++ versions 6, 7 and 8 the major versions are 12, 13, and 14 respectively).
- At this point, change directory (cd) to your copy of the \dev directory (if using Subversion) or the \gpstk directory (if using the tarball) of the toolkit, i.e. the directory that contains Jamrules, and simply type
jam to build the entire toolkit. Jam will tell you which compiler you are using, and then get to work. To install, define the environment variable
PREFIX to point to the root of the installation and then type
- Note 1. You could install BOTH MS compilers, in different directories, and then put all this setup into batch files that allow you to run either one independently. For example:
REM Batch file go2005.bat Run from the command line
REM before using jam and the MS 2005 build tools.
REM This is a copy of VSVARS32.bat that came with MS VC++ 2005
REM Move to my working directory
REM Batch file go2003.bat Run from the command line
REM before using jam and the MS 2003 build tools.
REM This is a copy of VSVARS32.bat that came with MS VC++.NET 2003
REM Move to my working directory
With these batch files the whole process is a simple as (a) open command window, (b) type go2005 (or go2003), (c) type jam. Type 'jam clean' to delete all the object (.obj) and executable (.exe) files.
- Note 2. The Jamrules file is where the MSCVER variable is required (unlike the MSVCNT variable, which the jam executable requires). If you use only one compiler exclusively, you might edit the Jamrules file and remove this version dependency; then you would not need MSCVER at all.
- Note 3. In any case you ought to look at the Jamrules file; look for $(NT), which the Windows executable jam.exe defines, for items relevant to Windows. C++FLAGS contains C++ compiler options, CCFLAGS contains C compiler options (but note that CCFLAGS is changed in \src\Jamfile for compiling regex.c), LINKFLAGS are linker options, and LINKLIBS are extra libraries included in the link.
- Note 4. We have found that optimization is a practical necessity in building with these compilers. The option /O2 (that's capital 'oh' not 'zero') seems to be best for speed. Jamrules now includes /O2 in both versions of the MS compilers. Of course you may change this, or any compiler or linker options, by editing Jamrules.
- Note 5. In the past one of the problems in using jam with the MS compilers beyond version 6.0 has been that the libraries advapi32.lib and kernel32.lib seemed to be missing. This, however, comes from the jam executable, not from MS. These libraries are required, and provided, in MS VC++ 6.0, and this is the default for the jam executable. Jam.exe does this by defining the default LINKLIBS to include these libraries. Since they are not required for later versions, Jamrules now redefines LINKLIBS to be empty. If you want to understand the defaults in jam.exe, go to the jam website and find the Jambase file - it is a 'Jamrules' file that contains all the defaults.
Apart from the instructions described above, here is another receipt for using GPSTk core libraries in Visual Studio 200X without using Jam:
- Download the project source files from Sourceforge and extract the tar files to a directory.
- In VS create a new Win32 console application project. (In order to avoid using precompiled headers, you must select 'Empty Project' option in the application wizard dialog)
- Right click on the project name (this is the name that is specified during creation of the project) in the solution explorer and click on Add -> Existing Item and add ALL the files in the 'src' directory (under the extracted files location that is created in step 1) to the project.
- (Again) Right click on project name in the solution explorer and click on Add -> Existing Item and add only 'example1.cpp' which is located under the examples directory.
- Open the project property page (Right click on the project name in the solution explorer and select properties)
- In the opened properties dialog expand the Configuration Properties -> C/C++ tab and select Command Line. Copy the following line to the Additional Options text box:
-D_CRT_SECURE_NO_DEPRECATE -wd4274 -DWIN32 /EHsc /GR -wd4290 -wd4267
- Again in the same project properties dialog box expand Configuration Properties -> C/C++ tab and select General. Add the location of 'src' directory to the Additional Include Directories. (This is necessary because, unfortunately, some non-system header files in the source files were included using < >)
- That is all. Build the program (building takes some time) and run. You will see the output of example1 in the output window.
You can also build a GPSTk library in the same manner to add all the core functions to your custom programs (but this time select 'Static Library' under the 'Application Setting' in the 'Application Wizard' to build the project as a library and of course do not add any example to the project).