Author Topic: How to compile Simutrans with MSVC  (Read 291 times)

0 Members and 1 Guest are viewing this topic.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8576
  • Total likes: 256
  • Helpful: 226
  • Languages: De,EN,JP
How to compile Simutrans with MSVC
« on: January 21, 2017, 08:57:45 AM »
This documentation is for MSVC express 2012. Since MS has the nice habit to break stuff more and more with each revision, it will probably not work with newer versions with fiddling around.

It is quite easy - I almost feel sorry to spare you from recompiling dependencies with GCC and such jokes. Well, real hackers don't have to follow :D

1 ) Download Microsoft Visual C++ express - for free,
2 ) install it.
3 ) Download precompiled libraries for OpenTTD - follow link with highest number, then download the zip file with binary data; its name might include win and should not contain source or ***sum.
4 ) Unpack this zip file somewhere - as an example, C:\example\ottd_libs. Inside this folder you should have a bunch of folders, namely win32 and shared.
5 ) Download this zip with the compiled bz2lib for MSVC or use the 7z file from below. The .h files goes to shared/include and .lib (from win32\ in the OpenTTD case) to win32/library.
6 ) Get the pthreads library for Win32. From the folders select the one with highest prebuilt-dll-x-y-z-release number. You should know now where the lib and h files go ...
Important: You need the DLL. Put it where your pak folders are!
7 ) Start MSVC and in menu, go to options (tools->options), a window opens with another set of choices to the left, you want to change directories (projects and solutions->VC++ Directories);
8 ) the dropdown menu in the top-right corner (it says Executable files at first) - set it to include files and add to list folder shared/include from the downloaded archive - example, C:\example\shared\include.
9 ) Do the same with library files - add there win32/library - example C:\example\win32\library.

Now you're set up for compiling - but don't have the sources!

10) Install Tortoise SVN (it integrates into Explorer).
11) Create new folder - eg. simutrans_src.
12) Click on it with right mouse button - choose SVN Checkout. A window pops up.
13) URL is svn:// - Leave the other options be, they're all correct.
14) OK!
15) If asked for password, enter user anon and leave password empty.
16) Downloading…

(Alternatively you can use the command line svn - that is not material for this guide as it's aimed for click-and-go solution)

And now - Christamaaaaas!

17) In the folder downloaded from svn (maybe simutrans_src) go to simutrans\trunk - you can see the lot of source files.
18) Open file simutrans.vcproj.
19) It is from older version, you have to go through wizard for project file update. Again no need to change any settings.
20) Once this is completed, to the left should appear some stuff (Solution Simutrans blah blah). In menu, choose Build->build solution.
21) Waiting…
22) Simutrans executable appears in folder debug (inside the folder with sources is folder Debug).

If you want to run simutrans from MSVC for debugging, you need to change the project properties -> debug
THe command line needs to start with -use_workdir and the working directory should point to the simutrans folder than contains your pak-folders (and the DLL).

Hopefully this can replace the old instruction by VC (Thanks!) and does work again.

Offline DrSuperGood

Re: How to compile Simutrans with MSVC
« Reply #1 on: January 21, 2017, 03:42:05 PM »
Some additional notes thigh might help people interested in using MSVC to develop or build Simutrans...

Simutrans does build with MSVC 2015 Community. I personally would recommend this over 2012 express as it is the full MSVC 2015 product (newer) for free with quite a good licence (even allows small scale commercial use for free). I would not recommend MSVC 2017 Community at the time of posting as it is still in developer preview and might not be directly compatible with the Simutrans source code, at least for now. Do note that it might be harder to setup over 2012 express due to newer technologies in 2015.

Most of the dependant libraries can be self built using MSVC allowing for a more integrated, faster and optimized build. Some of the older, less maintained, ones might need one or two settings or code modifications to compile properly. If doing this make sure the library builds made are compatible with the Simutrans build, meaning they have to support the same types of linking. I would not recommend self-building building pthread as that is by far the most complex of the dependencies and has pretty good pre-made builds.

The SVN server is the same as the multiplayer listing server. This means if you cannot access the listing server you cannot access the SVN. At the time of posting this seems to be an intermittent problem with people living in the UK using a BT connection where it might be inaccessible for a few weeks every few months possibly due to a temporary IP block.

Offline River

Re: How to compile Simutrans with MSVC
« Reply #2 on: Today at 06:38:22 PM »
i'm unable to download the files from the german forum. i don't have sufficient rights or something.

Also why don't you by default include all these files? It makes it alot easier for everyone

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 4454
  • Total likes: 141
  • Helpful: 105
  • Languages: EN, NO
Re: How to compile Simutrans with MSVC
« Reply #3 on: Today at 07:14:02 PM »
Also why don't you by default include all these files? It makes it alot easier for everyone

There might be issues with licensing, and also who is responsible for these files.