Author Topic: How to compile Simutrans Extended with MSVC 2012  (Read 6701 times)

0 Members and 1 Guest are viewing this topic.

Offline Spenk009

How to compile Simutrans Extended with MSVC 2012
« on: December 29, 2014, 08:03:25 PM »
This is a guide from my recent experience with compiling Simutrans Extended. This is a snapshot of Dec 2014 on Windows 7 and your configuration may differ.

1. Install Microsoft Visual Studio 2012 (e.g. from here or any other place you like). Update the program to Update 4
2. Get the sources from GitHub: here. You can download the whole folder as a zip file on the right side of the page or sign up and fork your own branch. Extract it somewhere memorable (like "D:\Programming").
3. Download the precompiled libraries from OpenTTD here. Choose the highest version and download the openttd-useful-*.*-win.zip. Open this zip and extract the folders into a folder that is easily accessed and remembered. These folders (win32,shared) are the folders we base the steps up to 5b on.
4. Now we get the header and library files:  here and here. The .h file goes to shared/include and .lib to win32/library.
5. Next are the pthread files, here. Select the latest/highest "prebuilt-dll-..-..-..-release".
5a In the subfolders "/lib/x86/" you'll find the .lib files. Put these into your \win32\library\ folder.
5b In the include folder, you'll find pthread.h, sched.h and semaphore.h. Put these into shared\include\.
5c In the subfolders "/dll/x86/" you'll find pthreadVC2.dll and pthreadVCE2.dll. Download these, but don't move them into your headers/libraries folder. These files will go into the same folder as your final Simutrans.exe as they're needed to run Simutrans Extended.

6. Start MSVC 2012 Update 4 and open Simutrans-Extended.vcxproj. Now click on Project -> Simutrans-Extended Properties... -> Configuration Properties -> VC++ Directories. Click on "Include Directories" once and then on the right of the field you'll see some paths listed. Next to that is a down arrow. Click that and click on <Edit...> in the resulting dropdown. On the top left of the window appearing you can add folders to the list. Add both \win32\library and \shared\include\ to this list. Things should be looking like this
7. Still in the Properties Window, select: Configuration Properties -> VC++ Directories -> Linker. In "Additional Library Directories" add the same folders as in step 6.
8. Now your build should compile.

9. Move the Created Simutrans.exe into a fresh folder.
10. Add the files from this .rar document to the folder.
11. Run your own compiled Simutrans!

Note: If you get an error with loadsave_t::start_tag(), delete or rename your Simutrans folder in My Documents.



This is a short guide to compiling your own pakset, specifically Pak128.Britain-Ex. I wrote this without going through it again, so I devised it from memory. If there are issues, let me know.

  • Install Python from here, I would go for 2.7.10 but this is open to your preference.
  • Install the MakeObject Script Engine from here.
  • Download a fresh copy of PakBritain from GitHub, the branch (above the file list) is currently "half-heights" as of May 2015. Extract this to a folder like in step 2 above.
  • Download the Extended Makeobj.exe from here. You will only need makeobj.exe and can move it into the PakBritain folder.
  • Find "makeALL.mos" in the main folder and edit the file with Notepad or similar. Replace config config "makeobj=%makeobj%" with "makeobj=makeobj.exe".
  • Run "makeALL.mos".
  • Wait for the script to complete, which usually takes a few minutes. While it does that, download the folders for inside the completed pak from here.
  • When the script has finished, copy/move the "Pak128.Britain-Ex-0.9.X", from within original folder you extracted the GitHub sources in, to your previously compiled Simutrans Extended game folder.
  • Extract the folders for inside the completed pak from two steps ago into the "Pak128.Britain-Ex-0.9.X" folder.
  • Start Simutrans.exe to check whether the pak runs.
Thank you to jamespetts, VS, and all others in the project.

Moderator note: References to "Simutrans-Experimental" changed to "Simutrans-Extended" 13 February 2017.
« Last Edit: February 14, 2017, 12:33:08 AM by jamespetts »

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 14945
  • Total likes: 334
  • Helpful: 146
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #1 on: December 29, 2014, 08:14:35 PM »
Splendid - thank you for posting that. That will surely help people new to the code. I will sticky this.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Junna

Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #2 on: January 01, 2015, 02:43:08 AM »
I have been able to compile in the past, but now I get an error:

C2065: "remaining_wear_capacity", undeclared identifier, in weg.h

Is there a new dependency?

Offline DrSuperGood

Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #3 on: January 01, 2015, 05:17:53 AM »
The name of that indicates an internal declaration inside the solution (not many standard libraries would use "remaining_wear_capacity" as a name). Either you have forgotten to update one of the files or there is currently a compile error in the GIT.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 14945
  • Total likes: 334
  • Helpful: 146
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #4 on: January 01, 2015, 10:38:54 AM »
Ahh - did some of my way wear mechanics accidentally make it into way-improvements? My apologies. If you are on the way-improvements branch, you can delete references to remaining_wear_capacity for now: this feature will be added in when you merge from the new way-wear branch.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Junna

Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #5 on: January 01, 2015, 04:37:37 PM »
Well, I don't know how to do that, I only use it to download the sources, I don't know how to actually use the git.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 14945
  • Total likes: 334
  • Helpful: 146
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #6 on: January 01, 2015, 04:57:37 PM »
It may be easier in that case to use your existing binary until I am able to fix it.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Rollmaterial

Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #7 on: July 16, 2015, 09:03:32 PM »
Thanks for this very helpful post! Does it apply to compiling in 64-bit too?

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 14945
  • Total likes: 334
  • Helpful: 146
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #8 on: July 16, 2015, 10:16:50 PM »
There are, I understand, some significant problems associated with the 64-bit version of Simutrans for Windows, which are part of the basic Simutrans code and not specific to Experimental. It is better to compile a 32-bit binary, which will run perfectly well on 64-bit Windows.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline DrSuperGood

Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #9 on: July 17, 2015, 01:24:24 AM »
Quote
There are, I understand, some significant problems associated with the 64-bit version of Simutrans for Windows, which are part of the basic Simutrans code and not specific to Experimental. It is better to compile a 32-bit binary, which will run perfectly well on 64-bit Windows.
64bit standard simutrans builds with MSVC and runs perfectly as far as I can tell. The only problem is that outside of allowing larger maps and paks it actually lowers performance due to worse memory density and less optimum cache usage. This is mostly due to some small but very common objects being made larger (less dense) and object references being larger.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 14945
  • Total likes: 334
  • Helpful: 146
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #10 on: July 17, 2015, 08:43:26 AM »
If I remember correctly, because of the internal memory pool systems using 32-bit integers, running in 64-bit mode does not allow the game to use more memory than it would running as a 32-bit application on a 64-bit operating system.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Rollmaterial

Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #11 on: October 31, 2015, 04:52:03 PM »
Which configuration should be compiled?

Offline DrSuperGood

Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #12 on: October 31, 2015, 05:43:03 PM »
32bit mostly. Only use 64bit if you encounter out of memory errors.

Offline Rollmaterial

Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #13 on: October 31, 2015, 05:50:03 PM »
32bit mostly. Only use 64bit if you encounter out of memory errors.
I mean between debug and release, but thanks for that as I could have memory problems too! By the way, how well should a 1026*1710 map work in 32 bit?

Offline DrSuperGood

Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #14 on: October 31, 2015, 05:52:23 PM »
Debug if you are a developer or plan to leave developer feedback or develop yourself, Release if you just want to play. Debug performs a lot slower but has full strack trace information for errors. Release it heavily optimized so performs better but on errors you get a lot of as good as garbage optimized code traces.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 14945
  • Total likes: 334
  • Helpful: 146
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #15 on: November 01, 2015, 10:01:35 PM »
Dr. Supergood is correct about debug/release. As to 32/64-bit, compile as 32 bit in Windows, and 64-bit for 64-bit Linux. Simutrans cannot work with a 64-bit address space and is not optimised for 64-bit use (the low level code was written long ago). A 64-bit build will work, but there is no advantage to it, except on Linux, where 32-bit builds do not work reliably on 64-bit versions of the operating system for some unknown reason.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline laos

Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #16 on: December 26, 2016, 07:24:17 PM »
The bzlib files are sadly 404ing. Any chance someone who has a copy can reupload them to this thread for those who wish to compile in Windows?

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 14945
  • Total likes: 334
  • Helpful: 146
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #17 on: December 26, 2016, 07:33:16 PM »
Sadly, I am not near my Windows computer that has a copy of these at present, as I am staying with my parents for Christmas; you might try searching online for it? I suspect that there must be a binary of this for Windows around somewhere.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline DrSuperGood

Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #18 on: December 26, 2016, 10:50:08 PM »
You can self build the library, which is what I did.

bzip2 I believe is the official site.

Offline laos

Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #19 on: December 28, 2016, 06:50:03 AM »
I found this github to be useful: https://github.com/philr/bzip2-windows/releases

the "developer files" include the related .h and .lib - I also happened to need the .dll when launching :)

So far was able to get win32 to compile. x64 is not working (getting a lot of different header and library file requests including SDL and allegro) - not sure if I'm doing something wrong as I'm not very adept with Visual Studio.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 14945
  • Total likes: 334
  • Helpful: 146
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to compile Simutrans Experimental with MSVC 2012
« Reply #20 on: December 28, 2016, 12:02:35 PM »
You do not need to compile the 64-bit version; there is no advantage to doing so, since Simutrans in any event uses an internal memory management system that cannot take advantage of more than 4Gb of RAM. There are no significant systems in Simutrans that take advantage of actual 64-bit computation. Although I have compiled Windows 64-bit versions in the past, I have not done so recently, and the code would probably need updating to allow for this.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.