Compiling For XP With Visual Studio 2019 on Windows10

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Compiling For XP With Visual Studio 2019 on Windows10

Post by wallyweb »

DISCLAIMER: This is a development problem. Does this topic belong here or in the OpenTTD Problem section?

PROBLEM: Using MinGW I am able to compile OpenTTD 1.8.0, but 1.9.0 fails in both nightly and beta:
[+] Spoiler

Code: Select all

$ make
make[1]: Entering directory `/usr/home/Wall/4_OTTD_nightly/2_compile/openttd-1.9
.0-RC2/objs/lang'
[LANG] Compiling core/alloc_func.cpp
C:/MinGW/msys/1.0/home/Wall/4_OTTD_nightly/2_compile/openttd-1.9.0-RC2/src/core/
alloc_func.cpp: In function 'void MallocError(size_t)':
C:/MinGW/msys/1.0/home/Wall/4_OTTD_nightly/2_compile/openttd-1.9.0-RC2/src/core/
alloc_func.cpp:22:68: warning: use of 'I' length modifier with 'u' type characte
r has either no effect or undefined behavior [-Wformat=]
  error("Out of memory. Cannot allocate " PRINTF_SIZE " bytes", size);
                                                                    ^
C:/MinGW/msys/1.0/home/Wall/4_OTTD_nightly/2_compile/openttd-1.9.0-RC2/src/core/
alloc_func.cpp: In function 'void ReallocError(size_t)':
C:/MinGW/msys/1.0/home/Wall/4_OTTD_nightly/2_compile/openttd-1.9.0-RC2/src/core/
alloc_func.cpp:31:70: warning: use of 'I' length modifier with 'u' type characte
r has either no effect or undefined behavior [-Wformat=]
  error("Out of memory. Cannot reallocate " PRINTF_SIZE " bytes", size);
                                                                      ^
[LANG] Compiling string.cpp
C:/MinGW/msys/1.0/home/Wall/4_OTTD_nightly/2_compile/openttd-1.9.0-RC2/src/strin
g.cpp: In function 'char* strcasestr(const char*, const char*)':
C:/MinGW/msys/1.0/home/Wall/4_OTTD_nightly/2_compile/openttd-1.9.0-RC2/src/strin
g.cpp:548:47: error: 'strncasecmp' was not declared in this scope
   if (strncasecmp(haystack, needle, needle_len) == 0) return const_cast<char *>
(haystack);
                                               ^
C:/MinGW/msys/1.0/home/Wall/4_OTTD_nightly/2_compile/openttd-1.9.0-RC2/src/strin
g.cpp: In function 'int strnatcmp(const char*, const char*, bool)':
C:/MinGW/msys/1.0/home/Wall/4_OTTD_nightly/2_compile/openttd-1.9.0-RC2/src/strin
g.cpp:606:26: error: 'strcasecmp' was not declared in this scope
  return strcasecmp(s1, s2);
                          ^
make[1]: *** [string.o] Error 1
make[1]: Leaving directory `/usr/home/Wall/4_OTTD_nightly/2_compile/openttd-1.9.
0-RC2/objs/lang'
make: *** [all] Error 1
DISCUSSION: This issue coincides with the move to Git.
There may be a problem with the required packages. Did a package change or was a new package introduced?
I went to the Compiling section of the OpenTTD Development page to review the libraries.
This page has the following note:
For further instructions on how to properly set up your system to build OpenTTD, take a look at our wiki page about development environments.
That wiki page is titled Coding Tools. On March 17 it was deleted by andythenorth with the comment "(Strongly outdated, no need to keep)". There was no suggestion for an alternate source for instructions on how to properly set up a system to build OpenTTD nor any discussion concerning development environments.

So, now I must question the validity of the library list with respect to MinGW. Is the page Compiling on Windows using MinGW still valid?
Are the libraries the source of my problem?
Last edited by wallyweb on 14 Apr 2019 07:40, edited 4 times in total.
User avatar
glx
OpenTTD Developer
OpenTTD Developer
Posts: 622
Joined: 02 Dec 2005 15:43
Location: Drancy(93) - France
Contact:

Re: Compiling Issue With MinGW

Post by glx »

Compilation is indeed broken with MSYS/MinGW, but with MSYS2/MinGW-w64 there's no issues. You can follow instructions on the page Compiling on Windows using MSYS2
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Compiling Issue With MinGW

Post by wallyweb »

glx wrote:Compilation is indeed broken with MSYS/MinGW, but with MSYS2/MinGW-w64 there's no issues. You can follow instructions on the page Compiling on Windows using MSYS2
Thank you very much. :bow:
This gives me exactly what I was looking for. Installation begins tomorrow morning.
If there are any questions, they will be posted below.
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Compiling Issue With MinGW

Post by wallyweb »

Apparently msys2 has abandoned Windows XP support:
MSYS2 homepage wrote:Current MSYS2 can't be installed on Windows XP anymore.
I have poked about their website and am unable to find an archive of older versions.
Any suggestions (other than upgrade my system)?
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Compiling Issue With MinGW

Post by wallyweb »

Archive found! :D

Cygwin ended its XP support in April 2016, so I went with msys2-i686-20160205.e x e 05-Feb-2016 18:12
It's not exactly as posted on the OpenTTD wiki instruction page, but it's close.
I just need to iron out a couple of bugs (probably mine) and then I will post my comments below, probably tomorrow.
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Compiling Issue With MinGW

Post by wallyweb »

wallyweb wrote:... msys2-i686-20160205.e x e 05-Feb-2016 18:12 ...
It's not exactly as posted on the OpenTTD wiki instruction page, but it's close.
I just need to iron out a couple of bugs (probably mine) and then I will post my comments below.
This was not a smooth experience. The installer did not refuse WindowsXP ... BUT ... compiling did not get past ./configure.
SOLUTION:
1. Buy a refurbished Window10 laptop.
2. Install MSYS2 - msys2-x86_64-20180531.exe
3. Test with MinGW32 to get an OpenTTD 32 bit compilation.
4. ./configure produced:

Code: Select all

WARNING: liblzo2 was not detected or disabled
WARNING: OpenTTD doesn't require liblzo2, but it does mean that
WARNING: loading old savegames/scenarios will be disabled.
configure: error: no liblzo2 detected
If you want to compile without liblzo2 use --without-liblzo2 as parameter
5. Compiled without liblzo2
6. A game saved on WindowsXP loaded without problem.
QUESTION:
What is meant by "old savegames/scenarios"?

Note that liblzo2-2.10-2-x86_64.pkg.tar.xz does exist in MSYS2 and there were no problems when compiling OpenTTD under MinGW64.
Eddi
Tycoon
Tycoon
Posts: 8258
Joined: 17 Jan 2007 00:14

Re: Compiling With MinGW2 on Windows XP - Drastic Solution

Post by Eddi »

"old savegames" means "savegames created with [very] old versions of OpenTTD", e.g. the title savegame of the trunk/nightly version which is probably almost 15 years old now. which exact savegames are affected probably depends on what game versions and settings the person making the savegames used. it is technically still possible to make such savegames with the current version of the game, but you need some fairly deep understanding of settings to even set that up.
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Compiling With MinGW2 on Windows XP - Drastic Solution

Post by wallyweb »

Eddi wrote:...
Thanks Eddi. :bow:
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Compiling With MinGW2 on Windows XP - Drastic Solution

Post by wallyweb »

Compiled OpenTTD master using MinGW32 on Windows10.
Executable works fine in Windows10.
Copied the file to WindowsXP.
Got this runtime error:

Code: Select all

The procedure entry point _except_handler4_common could not be located in the dynamic link library msvcrt.dll
msvcrt.dll does exist in my WindowsXP System32 folder.

Any thoughts or suggestions?
User avatar
orudge
Administrator
Administrator
Posts: 25134
Joined: 26 Jan 2001 20:18
Skype: orudge
Location: Banchory, UK
Contact:

Re: Compiling With MinGW2 on Windows XP - Drastic Solution

Post by orudge »

You'd need to use an older version of mingw32 (but one new enough to support the C++11 functionality that we use). I couldn't say precisely which version would be appropriate though, I'm afraid.

You could also install Visual Studio Community 2017 then switch the OpenTTD project to use the v140_xp compiler, which should produce an executable that will run on XP SP3 at least. (You'll need to tick the "Windows XP support for C++" option in the "Individual components" tab of the installer.)
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Compiling With MinGW2 on Windows XP - Drastic Solution

Post by wallyweb »

Hello Owen,

Thank you for looking in on this.

I did not know that MinGW32 was available as a standalone. The installer is for msys2 with MinGW32 and 64 seeming to be integral to the bundle. A previous attempt to install Visual C++ was too much of a challenge and I was driven to MinGW/msys which worked fine until the transition from XP to 7 and 10.

Apparently this is a known issue as described here

A couple of days ago I used the OpenTTD 1.9.0 stable 32bit installer on my XP box with no issues.
I then used msys2/MinGW32 on my Windos10 laptop and complied the source code available from the same page. I then moved that executable to my XP box and got the same old error.
Now, I assume that the OpenTTD crew used the same source code to build the installer version.
So now the question is what is the difference between OpenTTD's compiler and msys2?
Would it be safe to borrow msvcrt.dll from my 10 machine and copy it into XP?

Regards,

Wally
User avatar
orudge
Administrator
Administrator
Posts: 25134
Joined: 26 Jan 2001 20:18
Skype: orudge
Location: Banchory, UK
Contact:

Re: Compiling With MinGW2 on Windows XP - Drastic Solution

Post by orudge »

The build log is available here - OpenTTD's build system uses MSVC.

I'd probably suggest downloading Visual Studio Community (these days it's quite straightforward to install) - "desktop development for C++" should be sufficient hopefully. After installing Visual Studio, you'll also need to install vcpkg and integrate it (steps listed in the readme there), then run:

vcpkg install bzip2:x86-windows-static liblzma:x86-windows-static libpng:x86-windows-static lzo:x86-windows-static zlib:x86-windows-static bzip2:x64-windows-static liblzma:x64-windows-static libpng:x64-windows-static lzo:x64-windows-static zlib:x64-windows-static

Then you should be able to open the OpenTTD Visual Studio solution and build it, hopefully.

Copying msvcrt.dll from Windows 10 to Windows XP is likely a very bad idea - although once upon a time it was a somewhat independent library (being the Visual C++ 6.0 C runtime DLL), these days it's shipped with the OS and probably contains OS-specific hooks. And actually, checking the DLL on my system, it has a minimum Windows version of 10.0 baked into it, so it wouldn't work anyway.
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Compiling With MinGW2 on Windows XP - Drastic Solution

Post by wallyweb »

orudge wrote:I'd probably suggest downloading Visual Studio Community (these days it's quite straightforward to install) - "desktop development for C++" should be sufficient hopefully. After installing Visual Studio, you'll also need to install vcpkg and integrate it (steps listed in the readme there),
I think Visual Studio (VS) installed properly.
The VS "start?" page offers a prominent option to clone or check out code.
The vcpkg readme offers a link to its git repository.
The git code was downloaded and installation proceeded automatically.
then run:

vcpkg install bzip2:x86-windows-static liblzma:x86-windows-static libpng:x86-windows-static lzo:x86-windows-static zlib:x86-windows-static bzip2:x64-windows-static liblzma:x64-windows-static libpng:x64-windows-static lzo:x64-windows-static zlib:x64-windows-static
Where does one invoke "run"? This is not obvious. There is no cursor after which to type the install instruction. The help page offers nothing obvious, nor does the readme.
User avatar
orudge
Administrator
Administrator
Posts: 25134
Joined: 26 Jan 2001 20:18
Skype: orudge
Location: Banchory, UK
Contact:

Re: Compiling With MinGW2 on Windows XP - Drastic Solution

Post by orudge »

That should be in a command prompt. Something like:

mkdir c:\various\vcpkg
cd /d c:\various\vcpkg
git clone https://github.com/Microsoft/vcpkg
bootstrap-vcpkg
vcpkg integrate install
vcpkg install bzip2:x86-windows-static liblzma:x86-windows-static libpng:x86-windows-static lzo:x86-windows-static zlib:x86-windows-static bzip2:x64-windows-static liblzma:x64-windows-static libpng:x64-windows-static lzo:x64-windows-static zlib:x64-windows-static

Then you should be able to open Visual Studio, point it at the OpenTTD solution (projects\openttd_vs142.sln), and hopefully build it. I still can't guarantee that the generated build will work on Windows XP though!
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Compiling With MinGW2 on Windows XP - Drastic Solution

Post by wallyweb »

orudge wrote:Then you should be able to open Visual Studio, point it at the OpenTTD solution (projects\openttd_vs142.sln), and hopefully build it. I still can't guarantee that the generated build will work on Windows XP though!
Build failed:

Code: Select all

Severity	Code	Description	Project	File	Line	Suppression State
Error	C1083	Cannot open include file: 'ft2build.h': No such file or directory (compiling source file ..\src\fontcache.cpp)	openttd	C:\Users\User\source\repos\OpenTTD\src\fontdetection.h	19	
Error	C1083	Cannot open include file: 'ft2build.h': No such file or directory (compiling source file ..\src\fontdetection.cpp)	openttd	C:\Users\User\source\repos\OpenTTD\src\fontdetection.h	19	
Error	C1083	Cannot open include file: 'ft2build.h': No such file or directory	openttd	C:\Users\User\source\repos\OpenTTD\src\crashlog.cpp	52	
Error	C1083	Cannot open include file: 'ft2build.h': No such file or directory (compiling source file ..\src\strings.cpp)	openttd	C:\Users\User\source\repos\OpenTTD\src\fontdetection.h	19	
I searched in src. ft2build.h is not there.
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Compiling With MinGW2 on Windows XP - Drastic Solution

Post by Alberth »

Indeed, there is no ft2build.h in src. It's at /usr/include/freetype2/ft2build.h at my system, that is, part of the freetype2 library.
Being a retired OpenTTD developer does not mean I know what I am doing.
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Compiling With MinGW2 on Windows XP - Drastic Solution

Post by wallyweb »

Alberth wrote:Indeed, there is no ft2build.h in src. It's at /usr/include/freetype2/ft2build.h at my system, that is, part of the freetype2 library.
Thanks Alberth.
I found it on my system at C:\msys64\mingw32\include\freetype2\ft2build.h
Now the question is how to get it into Visual Studio 2019.
vcpkg does have freetype, but I do not see freetype2.
I ran vcpkg install freetype, and then recompiled openttd_vs142 but got the same errors.
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: Compiling With MinGW2 on Windows XP - Drastic Solution

Post by michael blunck »

@wally
It's called "change for change's sake". :twisted:

regards
Michael
Image
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Compiling With MinGW2 on Windows XP - Drastic Solution

Post by Alberth »

wallyweb wrote:
Alberth wrote:Indeed, there is no ft2build.h in src. It's at /usr/include/freetype2/ft2build.h at my system, that is, part of the freetype2 library.
Thanks Alberth.
I found it on my system at C:\msys64\mingw32\include\freetype2\ft2build.h
Now the question is how to get it into Visual Studio 2019.
vcpkg does have freetype, but I do not see freetype2.
I ran vcpkg install freetype, and then recompiled openttd_vs142 but got the same errors.
The "2" in the filename indicates to me it's aiming at freetype2 instead.
I found https://github.com/ShiftMediaProject/freetype2 , which aims to create visual studio freetype2. As I have no Windows at all, I can't say if it is useful or even how to install/fix things, but maybe you can figure it out or someone else can help?
Being a retired OpenTTD developer does not mean I know what I am doing.
User avatar
orudge
Administrator
Administrator
Posts: 25134
Joined: 26 Jan 2001 20:18
Skype: orudge
Location: Banchory, UK
Contact:

Re: Compiling With MinGW2 on Windows XP - Drastic Solution

Post by orudge »

wallyweb wrote:
Alberth wrote:Indeed, there is no ft2build.h in src. It's at /usr/include/freetype2/ft2build.h at my system, that is, part of the freetype2 library.
Thanks Alberth.
I found it on my system at C:\msys64\mingw32\include\freetype2\ft2build.h
Now the question is how to get it into Visual Studio 2019.
vcpkg does have freetype, but I do not see freetype2.
I ran vcpkg install freetype, and then recompiled openttd_vs142 but got the same errors.
I missed freetype from the vcpkg list (thought it had removed on Windows, but it was only a PR). You need to install freetype:x86-windows-static and freetype:x64-windows-static. Despite the name, it is freetype2.

OpenTTD requires the “windows-static” variants - it won’t pick up the regular version.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 13 guests