Configure_visual_studio_2015 - PIK-LPJmL/LPJmL GitHub Wiki

Configure visual studio 2015

[[TOC]]

How to get the software

Microsoft free version of the Visual Studio allows you to download the program, including a debugger. You can get it at https://www.visualstudio.com/downloads/ and choose Visual Studio Community.

The link might only work for the newest version 2017, since that is available now. You should still be able to download the 2015 version at https://www.microsoft.com/de-DE/download/details.aspx?id=48146 or https://www.visualstudio.com/vs/older-downloads/.

If you are working with windows systems anyway, this is a nice and handy developer environment. The main difference to alternatives (eclipse, text editors, etc.) is that VS uses no makefiles. Instead, you’ll have to configure the project by hand.

However, you still may use the makefiles supplied with the code in windows systems, if you have VS C installed.

SVN management

The plugin VisualSVN (download here allows for smoothly integrating the SVN functionality of Tortoise in Visual Studio and really makes things nice there.
However, it seems that PIK computers are member of an Active Directory domain, so buying a license is needed… :-(

Setting up a VS project

Click near the icon in the upper left to start a new project a new project on the downward arrow and choose ‘start project from existing code’, which starts a project wizard:

  • What type of project: Visual C
    • general properties
      • name your project
      • enter file location
      • check “add files to project from these folders”
      • check “add subfolders”
      • check “show all files in Solution Explorer”
      • project type
      • check “Use Visual Studio”
    • project type: “console application project”
    • click finish, the rest can be specified later

In case you are not able to create a project (error message: “Exception from HRESULT: 0x80041FE2”), go to the Windows control panel -> uninstall a program -> VS2015 -> ‘right click’: change -> MODIFY -> drop down menu: Programming Languages -> Visual C -> check the box: ‘Windows XP Support for C’ -> Update
That should solve the problem and you can now create a project from existing code.

After the project has been created, you need to exclude all .c files from the project that are not essential to the code. This can be done in the Solution Explorer (upper left hand corner).

  • exclude all files from the project that are not LPJ-essential (right click -> exclude from project). This comprises in directory src: the files nooutput_gwb.c and albedo.c in directory lpj, the directories oracle, utils, in directory pnet the files pnetinitf.c (if it exists) and pnet_reversef.c (if it exists) and the files update_build.c and lpj_climber.c (or now called: lpj_climber4. Note that in Visual Studio 2017 it is not possible to exclude entire folders, but only individual files.

Finally, you need to specify the project properties. For this, right-click on the project in the Solution Explorer.
configuration properties:

  • General:
    • character set -> use Multi-Byte Character Set
    • IMPORTANT: if you want to run the executable also on other computers you need to statically link the libraries to the exe file. For this, choose “Use MFC in static library” for the “Use of MFC” option. Otherwise, this can remain with the “Use Standard Windows Libraries”
  • Debugging:
    • Command arguments lpjml.conf
    • here, you can specify your working directory
  • C/C
    • General:
      • Additional Include directories: add the ../include directory here
      • Debug Information Format: C7 Compatible (/Z7)
    • Optimization
      • disabled(or whatever you want)
    • Preprocessor
      • preprocessor definitions: basically, here all compiler Flags from the src/Makefile can be specified, but without the “-D” prefix.
      • Essential preprocessor definitions are: WIN32;_DEBUG;_CONSOLE;_USE_MATH_DEFINES;WITH_FPE;SAFE; _CRT_SECURE_NO_WARNINGS;USE_CPP
        optional: IMAGE
    • Code Generation
      • Enable Minimal Rebuild -> No
      • Basic Runtime Checks -> Default
    • Advanced
      • compile as -> compile as C code (/TC)
  • Linker
    • General
      • under ‘Enable Incremental Linking’ -> ‘NO (/INCREMENTAL:NO)’
    • Input
      • Additional Dependencies -> advapi32.lib ws2_32.lib

Done. Now right-click on the project in the Solution Explorer and select rebuild or build.

⚠️ **GitHub.com Fallback** ⚠️