Make Simutrans speak your language.

How to compile Simutrans with MS Visual Studio

Started by An_dz, July 14, 2019, 10:38:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


I'm currently trying to improve our Visual Studio solutions as they are pretty messy and outdated. I've both used Visual Studio Community 2019 and manually edited them to make them better.

According to Microsoft [1] these files should be backwards compatible down to ~VS2012. If you are using a VS older than 2019 and newer than 2012 please try to load the attached solutions and let me know how they work for you.

One of the changes I did is to always compile inside the build/ dir just like GCC (it won't conflict with GCC unless you really want to).

Another change for the Simutrans solution is that now it's a single solution file with 4 projects. Simutrans-Main is the project that holds the shared, non back-end specific, files; Simutrans GDI, Simutrans SDL2 and Simutrans Server all use Main to build the specific back-end executables.

And a final difference is that now there are 3 compilation configurations for the main executable. Debug remains the same, meant for developing; Stable is the old Release, meant for compiling stable versions; and Release continues to build optimised code but now using revision data just like debug, this is meant for creating optimised nightly builds for servers.

These project files should also be easier to maintain, when new source files are added to Simutrans you just need to add those files in the Simutrans-Main.vcxitems file in alphabetical order and it will compile correctly just like the Makefile.

Please test as if they have backwards compatibility as promised I'll replace the files in trunk

I also compiled all the latest versions of the libraries required for Simutrans with Visual Studio Community 2019 (MSVC v14.21). The attached solutions expect them, most notably pthread-win32 version 3 which is an upgrade from the current outdated version 2 we are using. All libraries are available as Debug and Release.

Download Dependencies (Compatible with VS 2015+)

Visual StudioOpen ProjectPre-built Libs Work
2019 CommunityFlawlessYes
2017 CommunityFlawlessYes
2015 CommunityFlawlessYes
2013 CommunityFlawlessNo*
2012 ExpressConverts firstNo*
2010 ExpressFails**Could not test
* You'll have to compile the dependency libs yourself.
** Any VS below 2012 is incompatible.

  • zlib 1.2.11 (static)
  • bzip2 1.0.8 (static)
  • libpng 1.6.37 (static)
  • pthread 3.0.0 (static)
  • SDL2 2.0.9 (dynamic)
  • freetype 2.10.1 (static)
  • miniupnpc 2.1 (dynamic)

Some information about compiling the dependencies as I ran into trouble compiling them:

All Release libraries were compiled without Whole Program Optimisation /GL to make them portable. If compiling yourself consider turning this flag on for more optimisations.

miniupnpc will simply refuse to work with static linking, and for dynamic you need to download the project file from GitHub (miniupnpc.vcxproj) as the stable release is older than this change and the old vcxproj does not contain a dll setting. And tweaking the old vcxproj is more time consuming than just updating it.
For minupnpc in Librarian add iphlpapi.lib to Additional Dependencies.

zlib debug requires to change the Runtime Library setting to Multi-threaded Debug (/MTd). You also need to remove ZLIB_WINAPI from the Preprocessor of both debug and release or add it to Simutrans. Release can't be used if compiling with assembly because of some security check.

bzip2 debug requires either enabling Function-level Linking or changing Debug Information Format to C7 compatible /Z7. The former is more easily portable as the debug info is inside the lib; it's the option used for this build.

The same above for bzip2 applies to freetype.

libpng needs to remove Treat Warnings as Errors otherwise you get errors when a warning about applying Spectre mitigation occurs. For Release it's also worth removing the Debug Information Format.

Pthread version 3 is available here. It's the same project from Sourceware. [1] [2] [3]


The times are changing and from revision r9703 the building of Simutrans relies on VCPKG for installing the libraries.

This makes life much easier on the expense of harddisk space and unknow origin of libraries.

The following steps are needed:

  • Download MSVC Studio Community edition.
  • Download github for Destop or whatever git tool and clone to and arbitary directory.
  • Run bootstrap-vcpkg.bat
  • Copy install-building-libs.bat from simutrans/trunk to this folder and execute it.
This installs the missing libraries in the path. You can then just compile.


Some of these changes broke the automatic building at github. (revision.h is not generated). I have no time & energy to fix this.
Parsley, sage, rosemary, and maggikraut.


Yes, I noticed as well. Since I broke it I fix it.


Times are changing faster, so here the new way to get Simutrans building on MSVC.

Install MSVC 2022 and select desktop development. Do not bother with the intergrated vcpkg, it is a pain in backside and required a "baseline" which seems some github vcpkg hash which meaning MS does not document. Make sure to have the english language pak also installed!

download micosoft/vcpkg from github. Open a cmd to that directory and start "bootstrap.bat" and then "vcpkg integrate install".

Checkout the simutrans code and select the Simutrans.sln.

In MSVC in the solution explorer window, select a startup project and build it. The libraries will be downloaded and installed automatically!