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

0 Members and 1 Guest are viewing this topic.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8823
  • Total likes: 323
  • Helpful: 229
  • 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 http://www.simutrans-forum.de/forum/index.php?page=Attachment&attachmentID=22880&h=80d291ab255fe9584ba174c40bd7dfb9b596ac25 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://servers.simutrans.org/simutrans - 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: March 29, 2017, 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: 4870
  • Total likes: 202
  • Helpful: 108
  • Languages: EN, NO
Re: How to compile Simutrans with MSVC
« Reply #3 on: March 29, 2017, 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.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2594
  • Total likes: 290
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: How to compile Simutrans with MSVC
« Reply #4 on: March 29, 2017, 10:52:12 PM »
And you can also compile those libraries by yourself, and even compile more recent versions (another reason they are not included).

Offline DrSuperGood

Re: How to compile Simutrans with MSVC
« Reply #5 on: March 30, 2017, 02:52:37 AM »
Simutrans does build fine with MSVC2017 community. No compatibility changes were required.

Offline Leartin

  • Devotee
  • *
  • Posts: 848
  • Total likes: 301
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: How to compile Simutrans with MSVC
« Reply #6 on: April 12, 2017, 09:51:40 AM »
Please split and move if not fitting here...

I'd like to eventually play around with the code a bit, even though I'm not as firm with computers as I'd like to be and definitelly can't program C yet.

So far, what discouraged me the most was the setup, since I use a Windows PC and somehow, it seems that makes everything way more complicated than it should be. It feels like if I had a running setup, with a nice and simple "compile"-button, I wouldn't mind messing around and waiting a few minutes to check whether what I did had the desired effect or ended in a catastrophy, so I could finally contribute some of my many ideas myself rather than annoy everyone.

I got a new PC yesterday, so this might be the perfect opportunity since I have to set up other stuff as well, and it's probably the moment in time where any setup would last longest. But before I go through the 22 steps outlined above, I have two alternate options:
A) I could use Linux via Virtual Box and use that to program fool around with code.
B) I have a rasperry pi with native linux, but very weak performance.
Would you say either could be easier to use than Windows, is there any significant advantage/disadvantage?

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8823
  • Total likes: 323
  • Helpful: 229
  • Languages: De,EN,JP
Re: How to compile Simutrans with MSVC
« Reply #7 on: April 12, 2017, 01:35:12 PM »
You can use the mingw2 (the two is important). That has become easier than MSVC for a simple compile; BUT for debugging there is nothing better than MSVC the gdb is a pain (if it works at all under windows with threads). Linux might be ok, but a full compile tends to be much slower in a virtual machine. (And building on the rasberry is likely taking close to an hour (on my netbook it took 45 min for a complete build, and that was faster than a rasberry).

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2594
  • Total likes: 290
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: How to compile Simutrans with MSVC
« Reply #8 on: April 12, 2017, 02:38:01 PM »
I prefer on Linux, but mine is a laptop not a virtual machine. But as you said you got this new computer yesterday it can probably run a Virtual Machine easily. But on Windows, nothing is better than MSVC, it will create the best executable for it.

The advantage of Linux over Windows as I see is that you don't need to care about dependencies, you install them with the package manager and you'll get notifications when they can be updated.

And you have more choice for IDE, I code with SublimeText and use gdb with QTCreator.

Though these can be achieved on Windows with MSYS2 + MinGW.

Offline Leartin

  • Devotee
  • *
  • Posts: 848
  • Total likes: 301
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: How to compile Simutrans with MSVC
« Reply #9 on: April 12, 2017, 07:05:33 PM »
Okay, I tried to go with MSVC.

I could not use Step 8 and 9, since that's depricated and needs to be done via "user property sheet". Not sure how, I followed the rest of the instructions, and once Simutrans was in Visual Studio, I went to Project - Properties to set the paths. Is that correct, and could it be changed in the guide?

Building threw the same error 15 times
error C1083: Cannot open include file: 'revision.h': No such file or directory
In simversion.h, which includes revision.h, I found a comment that revision.h would be generated externally - do I need to do something else to get revision.h, or would that be generated upon building if it was set up correctly?

Offline DrSuperGood

Re: How to compile Simutrans with MSVC
« Reply #10 on: April 12, 2017, 07:15:23 PM »
Quote
Building threw the same error 15 times
error C1083: Cannot open include file: 'revision.h': No such file or directory
In simversion.h, which includes revision.h, I found a comment that revision.h would be generated externally - do I need to do something else to get revision.h, or would that be generated upon building if it was set up correctly?
You need a SVN tool installed, like TortoiseSVN. The file is script built with the SVN version, so needs an SVN command line tool to get the revision string. The script might need to be added to the build process as well, not sure if the file is run by default in MSVC anymore.

One can also manually create the file to assign any revision string one wants.


Offline Leartin

  • Devotee
  • *
  • Posts: 848
  • Total likes: 301
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: How to compile Simutrans with MSVC
« Reply #11 on: April 12, 2017, 07:25:04 PM »
TortoiseSVN is installed, I used it to get the sources.

Could you walk me through adding a script to the building process, or some 'fake' revision.h, since it probably doesn't matter as long as I don't hand out what I compile.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2594
  • Total likes: 290
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: How to compile Simutrans with MSVC
« Reply #12 on: April 12, 2017, 09:17:46 PM »
Just create a file revision.h with content
Code: [Select]
#define REVISION 1
But the script should do it automatically with the correct number, no idea where revision.jse is defined in the project but it should be there.

Offline DrSuperGood

Re: How to compile Simutrans with MSVC
« Reply #13 on: April 12, 2017, 09:29:55 PM »
Quote
Could you walk me through adding a script to the building process, or some 'fake' revision.h, since it probably doesn't matter as long as I don't hand out what I compile.
Under project properites, make sure Build Events -> Pre-Build Event option Command Line is set to "cscript.exe //Nologo revision.jse" (without "").

Offline Leartin

  • Devotee
  • *
  • Posts: 848
  • Total likes: 301
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: How to compile Simutrans with MSVC
« Reply #14 on: April 13, 2017, 02:29:13 PM »
Thanks. The Command Line in project properties was set, so I went with creating a revision.h the way an_dz suggested.

Now I seem to have an issue with zlib. 8 Errors with _adler32 and various _gz[something]. Except for the underscore, all of them are in zconf.h in the shared OpenTTD essentials, which shows up as External Dependencies in the Solution Explorer. Is there something like an _zconf.h I still need?

Offline TurfIt

Re: How to compile Simutrans with MSVC
« Reply #15 on: April 13, 2017, 02:47:40 PM »
Interesting MinGW-w64 via MSYS2 now appears easier to setup than MSVC.... the older MinGW was a PITA.  If you want IDE single button compiling and MSVCs debugger (which would be beyond a beginner I think), then MSVC is good, notwithstanding the library dependency hell... If you can handle command line compiling, which you'd get with your suggested Linux environments anyway, then give MSYS2 a try. An_dz has a excellent step by step posted in this forum right below this one; Literally takes < 5 mins to get up and running.

For the revision scripts to work with MSVC, you need a svnversion.exe available. I'm not sure if TortoiseSVN installs it or not, but perhaps it's not on your path? From a command shell (cmd.exe), change to your source code directory, and try running svnversion.exe. If can't be found, then that's the issue.

Offline hreintke

Re: How to compile Simutrans with MSVC
« Reply #16 on: April 13, 2017, 03:56:33 PM »
Leartin,

I had the same issue with the compile errors.
It is related/due to the versions you take for the external dependencies.

Need to check which version I now have which compiles and works as expected.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8823
  • Total likes: 323
  • Helpful: 229
  • Languages: De,EN,JP
Re: How to compile Simutrans with MSVC
« Reply #17 on: April 13, 2017, 11:43:07 PM »
The best way is with MSVC to compile the libraries yourself. Otherwise you tend to be stuck with wrong namemangling. It may help to definen undefine ZCONFSTAT in the project setting.

And yes, setting up a new MSVC version is always a two day job (which why I stay with older versions as long as possible).

Offline hreintke

Re: How to compile Simutrans with MSVC
« Reply #18 on: April 14, 2017, 12:09:52 PM »
Leartin,

What I also had to do is to add ZLIB_WINAPI to the PreProcessor Definitions.
That is used within the zlib.h to get the right functions.

BTW, I am using MSVC 2013

Offline Leartin

  • Devotee
  • *
  • Posts: 848
  • Total likes: 301
  • Helpful: 44
  • !!!!!This user was banned for double posting!!!!!
  • Languages: DE, EN
Re: How to compile Simutrans with MSVC
« Reply #19 on: April 14, 2017, 12:37:31 PM »
hreintke,
I'll try to do this. I use Express 2012, since that was suggested in the instructions and I hoped it would make things simple.

I'll also install virtual Linux and see if I have more luck that way. I suppose i7-6700K 4x4,0 GHz, 16GB DDR4 RAM should be enough for a virtual machine to run smooth enough for my purposes.

Offline DrSuperGood

Re: How to compile Simutrans with MSVC
« Reply #20 on: April 14, 2017, 03:47:56 PM »
Quote
And yes, setting up a new MSVC version is always a two day job (which why I stay with older versions as long as possible).
MSVC2015->2017 was instant for me. Did not even have to rebuild dependencies.

I would recommend 2017 because you can get the community edition for free, which is pretty much the full MSVC product for small developers minus some enterprise only features. It certainly beats express.

One day a better MSVC project setup should be committed to the SVN...

Offline vzrenggamani

  • *
  • Posts: 81
  • Total likes: 11
  • Helpful: 0
  • SetanKothak Families :v :v
    • OpenWorld Tech
  • Languages: ID, EN, C++, HTML
Re: How to compile Simutrans with MSVC
« Reply #21 on: May 06, 2017, 02:54:09 PM »
Can we use appveyor for cloud building ? I always fail when compiling, error and error. I think the GitHub revision are late or something else but I think its my pc xD
Can someone update the tutorial ? Xamarin Studio and MSVC 2015 xD

Regrads,
VR

SIMUTRANS INDONESIA WEBSITE  <<< Indonesia Simutrans Addons Center And Web
HOPE YOU UNDERSTAND MY ENGLISH

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8823
  • Total likes: 323
  • Helpful: 229
  • Languages: De,EN,JP
Re: How to compile Simutrans with MSVC
« Reply #22 on: May 07, 2017, 12:57:10 PM »
The problem are the libaries. Unlike in the above manual, the best way is to compile zlib, bz2, and libpng yourself. The precompiled one tend to run into issues where some need predefines and other not, and that is different between various download sources.

There is also a daily build for windows available (actually there are three nightly builds, one even including execution in the Amazon cloud). See nightly.simutrans.com

Offline vzrenggamani

  • *
  • Posts: 81
  • Total likes: 11
  • Helpful: 0
  • SetanKothak Families :v :v
    • OpenWorld Tech
  • Languages: ID, EN, C++, HTML
Re: How to compile Simutrans with MSVC
« Reply #23 on: May 13, 2017, 07:33:39 AM »
can anyoone give the compiled libraries ? I am stuck with libraries and pthread.h , i dont know where to put those files ( pthread.h , zlib , and png.h ).
 

SIMUTRANS INDONESIA WEBSITE  <<< Indonesia Simutrans Addons Center And Web
HOPE YOU UNDERSTAND MY ENGLISH