The International Simutrans Forum

 

Author Topic: Problem compiling with MingW  (Read 11620 times)

0 Members and 1 Guest are viewing this topic.

Offline Milko

  • Devotee
  • *
  • Posts: 829
Problem compiling with MingW
« on: December 29, 2010, 12:10:32 PM »
Hi

I'm tryng to build sim-exp using MingW on WinxXp system.
It's first time I use MingW / gcc.

I installed MingW in c:\mingw
I downloaded simutrans source code in c:\exp2
I copy config.template into config.default
I edit config.default and uncomment BACKEND = gdi COLOUR_DEPTH = 16 OSTYPE = mingw
I download and install libraries bzip2-1.0.6 , lpng145 , zlib-1.2.5 (and I put in c:\exp2\libra)
I download openttd essentials

Next, using command line and being in C:\exp2, I use c:\mingw\msys\1.0\bin\make --include-dir=.\libra\lpng145 --include-dir=.\libra\zlib-1.2.5 --include-dir=.\libra\bzip2-1.0.6 --include-dir=.\openttd\win32\library --include-dir=.\openttd\shared\include

But this the result:
CC simsys_32_png.c
make: CC: Command not found
make: *** [simsys_32_png.o] Error 127

If anyone can help me or recommend a good tutorial I would be very grateful...

Giuseppe

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18763
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Problem compiling with MingW
« Reply #1 on: December 29, 2010, 12:32:42 PM »
Giuseppe,

I can't help you with MingW, I'm afraid, as I use MSVC++ 2010, which I rather recommend, as it's quite easy to use.

Offline Milko

  • Devotee
  • *
  • Posts: 829
Re: Problem compiling with MingW
« Reply #2 on: December 29, 2010, 01:06:21 PM »
Hi James

What do you think you have the "nightly" of simutrans-experimental? I was thinking that it is very uncomfortable carrying out tests on new versions having to compile the code. The difference can be seen above all with the "fix" of current version, if anyone has a problem that brings the game to crash it is disheartening to have to wait until the next release issued when the fix has already been done. In this way only the developers become attached to the game, everyone else has problems in having to build the game to avoid the crash and may prefer the standard version.
The tests I'm doing with "MinGW " were designed to test whether you can build the game from WinXP to target other platforms. Thus, it may be useful, so I could provide any of the versions nightly, only to allow all to use the patch and the new opportunities (if you give me the OK).
I need the MingW because I could make a compilation from a PC where I am not an administrator (during lunch breaks) and then MSVC + + is excluded (I can not install).
If you feel good I was also thinking .... why not try to ask if there is Wernieman to generate nightly experimental sim in addition to standard? perhaps those of Pak.Britain.Exp ....

Giuseppe

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18763
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Problem compiling with MingW
« Reply #3 on: December 29, 2010, 01:21:36 PM »
Giuseppe,

a nightly version of Experimental is a good idea indeed if there are resources sufficient to put it in place. I know very little about MingW, so I'd have to research as much as you would to put it together. Certainly, if you can set up MingW to work and produce nightlies for Windows, Mac and Linux, I'd be very grateful.

Wernieman has considered setting up nightlies for Experimental in the past, but seems to have had trouble interacting with Git. Perhaps you could talk to Wernieman  about how to use Git with MingW and/or Linux? Anything that you're able to do in this regard would be appreciated :-)

Offline Milko

  • Devotee
  • *
  • Posts: 829
Re: Problem compiling with MingW
« Reply #4 on: December 29, 2010, 03:50:20 PM »
Hello

To create nightly, which repositories should I use? the 9.x or devel? I do not understand the relationship that exists between the two, now it seems to me (but I'm not an expert on github) that the version 9.x is more updated than the devel. If I'm not mistaken, however, the devel is one that contains (or should contain) all the news and therefore should be the best one.

Giuseppe

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18763
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Problem compiling with MingW
« Reply #5 on: December 29, 2010, 03:57:57 PM »
Hmm, that's a difficult question, as the two are used for different things. 9.x is used for small changes and bug fixes, whereas devel is used for substantial new features. However, convenience dictates that development often takes place on either one or the other - but not both. Devel may well be the best to use for nightlies for the time being, although there may be some sense in using both 9.x and devel (or running a script to check which is the most recently updated of the two and making a nightly from that). Remember, there will come a time when 9.x is abandoned (like the 8.x branch before it) and development will move to 10.x.

Offline TurfIt

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 1327
Re: Problem compiling with MingW
« Reply #6 on: December 29, 2010, 09:48:57 PM »
If anyone can help me or recommend a good tutorial I would be very grateful...

The OpenTTD tutorial is about it - http://wiki.openttd.org/Compiling_on_MinGW. Although it's been drastically changed since I used it; So no idea how good it is now. I eventually got http://wiki.openttd.org/?title=Compiling_on_MinGW&oldid=36155 to work. Slightly newer http://wiki.openttd.org/?title=Compiling_on_MinGW&oldid=44519 is probably good too.

I think the only changes I required to get Simutrans compiling were:
1) keep the libraries in /mingw/{include,lib} rather than moving them to /usr/local/{include,lib} as per the tutorial. Atleast this version of MinGW doesn't include /usr/local in the gcc search path, so no idea why the tutorial is going there...
2) "cp /mingw/bin/gcc.exe /mingw/bin/cc.exe".  CC is missing in the MinGW install...
3) install SDL lib if desired to use SDL backend instead of GDI.


I downloaded simutrans source code in c:\exp2

 \msys\1.0\ is mounted as / in the msys file system. If you want to keep your source outside the msys path, you'll have to mount c:\exp2 to somewhere in the msys file system. Can edit /etc/fstab to have it automount every msys launch. Or simply put the source into /home/Milko


I download and install libraries bzip2-1.0.6 , lpng145 , zlib-1.2.5 (and I put in c:\exp2\libra)

Same here as with the source. You'll have to get this windows path mounted up into msys and also specify non-default search paths to gcc every invokation. Simpler to just install the libraries to the mingw default /mingw/{include,lib}.


Next, using command line and being in C:\exp2, I use c:\mingw\msys\1.0\bin\make --include-dir=.\libra\lpng145 --include-dir=.\libra\zlib-1.2.5 --include-dir=.\libra\bzip2-1.0.6 --include-dir=.\openttd\win32\library --include-dir=.\openttd\shared\include

 ???
 ??? ??? ???
Are you invoking make from a Windows cmd.exe prompt? You need to be in msys at a sh.exe prompt... There's no way sh.exe understands DOS drive letters/paths.  :::)
If the libraries are all installed correctly, there should be no need for --include-dir. Simply run make...

But this the result:
CC simsys_32_png.c
make: CC: Command not found
make: *** [simsys_32_png.o] Error 127

Fixed by 2) above. Not sure why the MinGW installer leaves cc out but...



Also, watch out for hardcoded include paths in the sim-exp code. e.g. #include "../SDL-1.2.13/include/SDL_syswm.h"  instead of #include <SDL/SDL_syswm.h>.
And for nasty #ifdef _WIN32  blocks that kill MinGW. i.e. sim-exp has been MSVCified unlike the nicely portable sim-standard...

As for a msys git - you're on your own. I ran into huge CR/LF issues with it and lost interest in sim-exp before resolving (if possible)...


Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18763
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Problem compiling with MingW
« Reply #7 on: December 29, 2010, 10:20:26 PM »
Also, watch out for hardcoded include paths in the sim-exp code. e.g. #include "../SDL-1.2.13/include/SDL_syswm.h"  instead of #include <SDL/SDL_syswm.h>.
And for nasty #ifdef _WIN32  blocks that kill MinGW. i.e. sim-exp has been MSVCified unlike the nicely portable sim-standard...

I'm trying to get rid of these issues; I have already recently disposed of a number of absolute paths in the MSVC++ project. I know that the Experimental code compiles well under Linux (as Linux nightlies are made); if you can spot any specific issues that cause problems with non-MSVC++ compiling, or any other portability issues, in the latest Simutrans-Experimental code, please let me know, and I'll try to replace it with something more portable.

Offline Milko

  • Devotee
  • *
  • Posts: 829
Re: Problem compiling with MingW
« Reply #8 on: December 30, 2010, 07:13:56 PM »
Hello TurfIt

Thanks. Your help is important. I moved the libraries in / mingw / {include, lib} and things go much better. The compilation was stirred but it was locked during the LD command, as in the image that I enclose.

Do you have any other help for me?


Offline TurfIt

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 1327
Re: Problem compiling with MingW
« Reply #9 on: January 02, 2011, 06:03:07 AM »
The libraries must still not be where the linker is expecting to find them.

I just reinstalled everything to see how it went ( had a new OS install so...)

Follow http://wiki.openttd.org/Compiling_on_MinGW down through the Compiling libpng section - Simutrans doesn't need the rest of the libraires.
Deviations I made from the guide:
  1) Selected "Use current repository catalogues".
  2) Selected "MinGW Developer ToolKit" to install.
  3) Used libpng-1.4.5 instead.
Don't know if this would make a difference...


cc.exe is called by the Simutrans Makefile and missing from the MinGW install
In MSYS:
Code: [Select]
cp /mingw/bin/gcc.exe /mingw/bin/cc.exe


bzip2 is needed for Simutrans: http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
No MinGW configuration so edit the makefile to change:
Code: [Select]
chmod a+x $(PREFIX)/bin/bzip2
chmod a+x $(PREFIX)/bin/bunzip2
chmod a+x $(PREFIX)/bin/bzcat
chmod a+x $(PREFIX)/bin/bzip2recover
to:
Code: [Select]
chmod a+x $(PREFIX)/bin/bzip2.exe
chmod a+x $(PREFIX)/bin/bunzip2.exe
chmod a+x $(PREFIX)/bin/bzcat.exe
chmod a+x $(PREFIX)/bin/bzip2recover.exe
or simply delete the lines... else the make will abort.

In MSYS run:
Code: [Select]
make install PREFIX=/mingw
to install.


For GDI - also require libunicows: http://prdownloads.sourceforge.net/libunicows/libunicows-1.1.1-mingw32.zip
Simply copy libunicows.a from the .zip into /mingw/lib


For SDL - also require SDL:
In MSYS:
Code: [Select]
wget http://www.libsdl.org/release/SDL-1.2.14.tar.gz
tar xvfz SDL-1.2.14.tar.gz
cd SDL-1.2.14
./configure ; make ; make install

Will need the SDL.dll in your Simutrans directory to run. It's found in /usr/local/bin/SDL.dll in MSYS or \MinGW\msys\1.0\local\bin\SDL.dll in Windows.
or copy the precompiled/stripped .dll from inside http://www.libsdl.org/release/SDL-devel-1.2.14-mingw32.tar.gz


I also added
Code: [Select]
 LDFLAGS += -static-libgcc -static-libstdc++
to the Simutrans Makefile MinGW section so I didn't need to hunt down even more dlls...


And, if you want to use the ./distribute.sh script you'll need a zip.exe: ftp://ftp.info-zip.org/pub/infozip/win32/zip300xn.zip. I stuck it into /bin


And finally I get something that successfully compiles and runs both Simutrans-standard and -experimental in both GDI and SDL formats. However, I doubt the -experimental version will run long - the compiler is choking on the "%lld" printf specifiers... sigh.


Edit: forgot about cc.exe
« Last Edit: January 02, 2011, 09:55:48 PM by TurfIt »

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18763
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Problem compiling with MingW
« Reply #10 on: January 02, 2011, 11:32:43 AM »
TurfIt,

thank you for your work on this. Do you think that you could upload your modified makefile with the MinGW instructions so that I can include it by default with Simutrans-Experimental to enable MinGW people to compile Experimental more easily? I do want to try to clean up the Experimental code and make it more portable if possible.

As to the %lld printf specifiers, why does MinGW not like them? They are, I understand, the C99 standard format specifier for outputting a 64-bit value (used in Simutrans for prices, and additionally in Simutrans Experimental for years).

Offline TurfIt

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 1327
Re: Problem compiling with MingW
« Reply #11 on: January 02, 2011, 09:36:46 PM »
thank you for your work on this. Do you think that you could upload your modified makefile with the MinGW instructions so that I can include it by default with Simutrans-Experimental to enable MinGW people to compile Experimental more easily? I do want to try to clean up the Experimental code and make it more portable if possible.

All I did was add a couple linker flags to statically link a couple libraries. It will compile just run without any changes to the Makefile - you just need to have the right .dlls when you try to run the resultant .exe. In trying to find the .dlls, I ran across the appropriate flags required to static link first - now no more bloody .dlls required.

Also, these .dlls are only needed for recent MinGW versions. My original MinGW install from early 2010 doesn't require them and doesn't understand the linker flags. i.e. Would need to create another OSTYPE in the Makefile to distinguish the MinGW versions.

The same applies to Simutrans-standard.


As to the %lld printf specifiers, why does MinGW not like them?

I guess because it's MinGW  ;D
Seriously, from what I can tell it's being blamed on that nasty MSVCRT.dll again (same as the %lf issue I had last year). Requires %I64d for signed 64bit integers. Not sure if your MSVC likes %I64d or not, but since MSVCRT is a MS file, I would think so...

MinGW from early 2010 - gcc version 3.4.5 (mingw-vista special r3)
MinGW from early 2011 - gcc version 4.5.0

gcc 3.4.5 appears happy with %lld.
gcc 4.5.0 gives:
Code: [Select]
===> CXX gui/depot_frame.cc
gui/depot_frame.cc: In member function 'virtual void depot_frame_t::zeichnen(koord, koord)':
gui/depot_frame.cc:595:102: warning: unknown conversion type character 'l' in format
gui/depot_frame.cc:595:102: warning: too many arguments for format
but appears to run ok. However, I haven't tested much at all.

Both versions appear happy with %I64d. Again not tested much.


As to the %lld printf specifiers, why does MinGW not like them? They are, I understand, the C99 standard format specifier for outputting a 64-bit value (used in Simutrans for prices, and additionally in Simutrans Experimental for years).

I didn't know Simutrans was programmed in C99; Kinda thought it was C++  ;)
Haven't been following the evolution of the languages or the tools implementing them. With all the various target platforms Simutrans is supporting, there's bound to be issues.

Note: Simutrans-standard doesn't have any %llds (except one in a debug printf). But, does include this:
Code: [Select]
"jahresgewinn = %ld\n" // %lld crashes mingw now, cast gewinn to long ...

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9595
  • Languages: De,EN,JP
Re: Problem compiling with MingW
« Reply #12 on: January 02, 2011, 10:26:37 PM »
Also GCC before 3.x did not like %lld ... And there is absolutely no portable way, since intypes.h is missing on some platformes or (like MinGW) give %lld, which is obviously not working when not linking statically. (Static linking with %lld did work, I think.)

Offline inkelyad

  • Devotees (Inactive)
  • *
  • Posts: 482
  • Languages: EN, RU
Re: Problem compiling with MingW
« Reply #13 on: January 02, 2011, 10:58:26 PM »
I didn't know Simutrans was programmed in C99; Kinda thought it was C++  ;)
Then we should use something like:
Code: [Select]
#include <sstream>
ostringstream output;
output << uint64_bit_variable;
It is C++ way.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9595
  • Languages: De,EN,JP
Re: Problem compiling with MingW
« Reply #14 on: January 03, 2011, 09:25:51 AM »
Simutrans started in 1997, so it pretty much rules out C99 ... it is C++ closed to the previous standard. The stuff using standard is very recent, only added in the last two years by tron. (That is the main reason for the use of own templates.)

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18763
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Problem compiling with MingW
« Reply #15 on: January 04, 2011, 11:08:18 AM »
TurfIt,

would it be possible for you to post your makefile with the OSTYPE distinctions for MinGW so that I can add it to the Github repository?

Offline TurfIt

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 1327
Re: Problem compiling with MingW
« Reply #16 on: January 09, 2011, 01:15:59 AM »
Here you go...
As I mentioned, it's not strictly necessary. It will compile just fine; You only need to make sure you have libgcc_s_dw2-1.dll and libstdc++-6.dll (atleast for the current MinGW version) somewhere if you don't static link them.

Offline Milko

  • Devotee
  • *
  • Posts: 829
Re: Problem compiling with MingW
« Reply #17 on: August 25, 2011, 10:38:24 AM »
Hi

Today i'm very happy.

After several attempts I managed to make simutrans exp! (GDI version)

This is the procedure I followed.

Configuring Mingw (only the first time):

copy /mingw/bin/gcc.exe into /mingw/bin/cc.exe

zlib:

download zlib125.zip (official site: http://zlib.net) and unzip in home/usr, folder will be created -> zlib-1.2.5

In msys:
cd zlib-1.2.5
make -f win32/Makefile.gcc BINARY_PATH=/mingw/bin INCLUDE_PATH=/mingw/include LIBRARY_PATH=/mingw/lib install
cd ..

bzip2:

download bzip2-1.0.6.tar.gz (official site: http://www.bzip.org) and unzip in home/usr, folder will be created -> bzip2-1.0.6

edit makefile and delete rows:
   chmod a+x $(PREFIX)/bin/bzip2
   chmod a+x $(PREFIX)/bin/bunzip2
   chmod a+x $(PREFIX)/bin/bzcat
   chmod a+x $(PREFIX)/bin/bzip2recover

In msys:
cd bzip2-1.0.6
make install PREFIX=/mingw
cd ..

GDI Library:

download http://prdownloads.sourceforge.net/libunicows/libunicows-1.1.1-mingw32.zip
the file libunicows-1.1.1-mingw32.zip contain libunicows.a, copy libunicows.a to c:/mingw/lib

End mingw configuration.

download simutrans code in home/user (i.e. in the folder exp10.0)

in exp10.0 rename config.template to config.default

edit config.default and uncomment BACKEND = gdi COLOUR_DEPTH = 16 OSTYPE = mingw

Make simutrans:
In msys:
cd exp10.0
make

simutrans.exe will be created in home/usr/build/default

WOW!

Thanks to all!

Giuseppe
« Last Edit: August 26, 2011, 09:54:17 AM by Milko »

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18763
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Problem compiling with MingW
« Reply #18 on: August 27, 2011, 03:15:35 PM »
Giuseppe,

glad that you managed to build it; and thank you for posting your instructions!

Offline Milko

  • Devotee
  • *
  • Posts: 829
Re: Problem compiling with MingW
« Reply #19 on: January 07, 2015, 10:15:54 PM »
Hello

To compile makeobject ...

Follow instruction to compile simutrans and next:

Configuring Mingw (only the first time):

libpng:

download libpng (official site: http://www.libpng.org/pub/png/libpng.html) and unzip in home/usr, folder will be created -> lpng1252 (Important, use version 1252)

In msys:
cd lpng1252
make -f scripts/makefile.gcc
cd..

copy libpng.a from home/usr/lpng1252 to c:/mingw/lib
copy png.h and pngconf.h from home/usr/lpng1252 to c:/mingw/include

End mingw configuration.

download simutrans code in home/user (i.e. in the folder exp10.0)

Make simutrans:
In msys:
cd exp10.0
cd makeobj
make

makeobj.exe will be created in home/usr/build/default/makeobj

EDIT: lpng version

EDIT 12/07/2016: png.h and pngconf.h

Giuseppe
« Last Edit: July 12, 2016, 10:15:03 AM by Milko »