View topic | Edit  | WYSIWYG Attach Printable PDF Subscribe Topic
r15 - 12 May 2009 - 22:19:59 - AllenFarrisYou are here: TWiki >  Documentation Web  >  BuildingGPSTkUnderUnix > BuildingGPSTkUnderWindows

Building under Microsoft Visual Studio

If you are building GPSTk under the Cygwin environment, then use the jam portion of BuildingGPSTkUnderUnix instructions.

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++.

  1. Ensure that prerequisites such as jam have been installed.
  2. Ensure that there is a system regular expression library installed. See InstallingRegexSupportForVisualCPP.
  3. 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.
  4. 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.
  5. 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:
          set MSVCNT=C:\MSVC2003\VC7
          set MSCVER=1300
    
    or if you are using the 2005 compiler instead:
          set MSVCNT=C:\MSVC2005\VC
          set MSCVER=1400
    
    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).
  6. 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 jam install.
  • 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.
          set MSVCNT=C:\MSVC2005\VC
          set MSCVER=1400
          REM This is a copy of VSVARS32.bat that came with MS VC++ 2005
          call VSVARS32_2005
          REM Move to my working directory
          cd C:\WorkingDirectory
    
    and
          REM Batch file go2003.bat  Run from the command line
          REM    before using jam and the MS 2003 build tools.
          set MSVCNT=C:\MSVC2003\VC7
          set MSCVER=1300
          REM This is a copy of VSVARS32.bat that came with MS VC++.NET 2003
          call VSVARS32_2003
          REM Move to my working directory
          cd C:\WorkingDirectory
    
    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:

  1. Download the project source files from Sourceforge and extract the tar files to a directory.
  2. 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)
  3. 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.
  4. (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.
  5. Open the project property page (Right click on the project name in the solution explorer and select properties)
  6. 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
  7. 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 < >) Also, add the location of the regex library that you have installed. This should contain a file regex.h.
  8. 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).

View topic | Edit |  | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r25 |r17 < r16 < r15 < r14 | More topic actions...
 
WEBLOGOALT
This site is powered by the TWiki collaboration platformCopyright amp; by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback