News:

Use the "Forum Search"
It may help you to find anything in the forum ;).

Compiled successfully on OS X

Started by zhaop, August 11, 2016, 04:11:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

zhaop

I was able to compile the latest master (Simutrans 112.3, Experimental 11.35; a1dada8844, 30 June 2014) on OS X El Capitan from the Terminal. In game, I was able to generate a 512 x 512 map and everything ran pretty smoothly. Haven't yet tested loading a well-developed save.

Here's my attempt at documenting the process. The following will be edited as I learn more.

After duplicating config.template into config.default, I set the backend to OpenGL, set OSTYPE to mac, DEBUG to 2, OPTIMISE to 1, and MULTI_THREAD to 4.

Then some of the code needs to be patched (see attached). Once it is applied:
make
cp build/default/simutrans-experimental simutrans/simutrans-experimental
mkdir simutrans/text
./get_lang_files.sh

Then download a pak & put into the simutrans/ directory.

This should give you a working game. Hope this helps anyone trying to compile Simutrans-Experimental 11.35 on OS X!

I do not yet recommend this patch to be pulled into the repo in its current form, because some basic safeguards are still lacking. Though if it is desired, I can work on a good pull-able patch. Also, it's possible I didn't mention any required libraries that I already had installed that I wasn't aware of.

Cheers!
I'm working on an AI for Simutrans that can make lots of money, and I'm currently learning the squirrel API for AI players.
https://github.com/zhaop/simutrans/tree/marmot

jamespetts

Hello - thank you for this: this is most helpful. I should note that I am not working on the master branch any longer, my efforts being concentrated on producing the next version in the devel-new branch. If you would like to make a patch for Mac compilation, I do suggest that you make it from that branch so that it can be integrated into the main code. It is very helpful to have working MacOS versions, though.
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.

zhaop

#2
Hi James! Thanks for the info.

I've pulled the devel-new branch (commit 22f51b, 10 Aug 2016) and did some patching here and there until it compiles & runs properly. Here's the patch!

I tried to make it so it's safe to merge; it should be tested on a non-Mac system to be sure.

It seems most of the issues this time come from Apple using clang++ (llvm) instead of g++ (gnu), so I've had to enforce things in the Makefile like -std=c++11 -stdlib=libstdc++ (on mac only) to have it as close as what I guess g++ does on Linux. Is this practice advisable?
I'm working on an AI for Simutrans that can make lots of money, and I'm currently learning the squirrel API for AI players.
https://github.com/zhaop/simutrans/tree/marmot

jamespetts

Splendid, thank you for that: I have now incorporated that. That is most helpful.

I am afraid that I know very little about Mac OS X compiling, so I cannot assist with whether what you suggest is the optimum strategy, but I should be grateful for anyone else's views on the point.
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.

ivan_holmes

Hi, I have tried to compile the latest devel-new version of simutrans and after a few hiccups managed to get it to compile. However, it will not link:
===> LD  build/default/simutrans-experimental
ld: library not found for -lGL
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [build/default/simutrans-experimental] Error 1


I have read that on Mac, you should use -framework OpenGL rather than -lGL but I have no idea where the -lGL option is coming from.

I have also tried to compile it using the SDL and SDL2 backends and they a humungous error message about 'Undefined symbols for architecture x86_64' which I cannot draw any useful information from.

Zhaop, did you have to get around this problem? If so, how?
Otherwise, I would really appreciate it if you would send me your binary.

Thanks,
Ivan

jamespetts

I can only offer a guess because I am not at all familiar with the Mac architecture, but I wonder whether the issue is that you are missing certain development libraries? I am not sure what "lGL" is, however; perhaps it is an OpenGL thing? Perhaps you need to install the OpenGL developer libraries?
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.

ivan_holmes

I was not particularly clear before - -lGL is a compiler flag telling the compiler to link with OpenGL development libraries.
-lGL is automatically passed as an argument to the compiler but I have run a search of the contents of all the files in the simutrans-experimental folder, and the string 'lGL' was not found, hence the source of my confusion.

Apple ship OpenGL development libraries as default - but they are shipped as a framework, so the purpose of -framework OpenGL is the same as the purpose of -lGL, just that lGL will work on Windows and Linux. If third party development libraries are available, I have no idea where to get them; I can't find anything on homebrew.

Thanks for your help James, hopefully zhaop will have a solution as my own Mac development experience is limited (mainly the development part).
Hopefully I can get this working.

TurfIt

The OpenGL backend is an abandoned experiment completely superseded by SDL2. Should probably just be removed...

The paths for SDL and SDL2 are wrong since they were set for the old nightly cross compiling server. A proper native OSX framework has the library else where.

Attached are the changes I use for compiling the Standard OSX release (SDL2 only). I've not tried it with Experimental.
Do note SDL2_CONFIG must be defined empty in config.default as instructed.

And, this only gets you the executable. I've found none of the scripts for bundling or even simply getting the translations work. So I just copy them from another system to get a working base package.

zhaop

#8
Here's a new patch to make the SDL2 backend work on Mac!

This is to be applied on top of the newest devel-new (which has my previous patch). My config.default file now has BACKEND = sdl2, and SDL2_CONFIG set to an empty string.


@TurfIt: Thank you for your notes; your file was especially helpful. For the record, OpenGL worked okay; the only undocumented features so far were crashing when going fullscreen, the "backspace" key being taken as "delete", and that the SDL2 version runs a little faster than the OpenGL version.

I've also found this interesting attempt at fixing Makefile for Macs. Your patch has a "mac32" target; it seems compiling that requires setting -DUSE_C and an i386 version of SDL2 for Mac (which I haven't yet been able to find).

I seem to have bundling ('make bundle_dist') working again (once OSX/plistgen.sh is chmod'd to u+x), though I haven't tested if the .app thus produced works on other "clean" Macs. At least it works even after I delete SDL2.framework from /Library/Frameworks.

As for the translations, do you mean the get_lang_files.sh script? It seems to work correctly for me after the missing folder simutrans/text is created (otherwise, the language files get put into where you run the script) (EDIT: ignore this, I made an incorrect wrong assumption), or maybe I'm missing something.


@ivan_holmes: Welcome to the forum ☺ I'm almost honored to have provoked someone into registering on this forum to reply (whether this is actually true or not)!

The immediate fix for the OpenGL backend is indeed to use "-framework OpenGL" instead of "-lGL" (this is in Makefile). You can find this change in my current patch. But it's better to switch to the SDL2 backend like TurfIt advises. You'll need to have SDL2.framework in /Library/Frameworks, the newest devel-new, and the attached patch to properly compile.


@jamespetts: Thank you for integrating my patch and including me in the credits!

I've noticed some of my changes in the Makefile didn't seem to have made it into the repo, which prevents successful compiling on Mac. So I've taken the liberty of adding them again to this patch, unless there are some reasons not to? Also, I've noticed you prefer git over patchfiles (how-to-get-the-sources.txt), so I'll be using that in the future!


EDIT: It may be useful to know that makeobj & nettool both compiled fine as-is on my Mac.
I'm working on an AI for Simutrans that can make lots of money, and I'm currently learning the squirrel API for AI players.
https://github.com/zhaop/simutrans/tree/marmot

ivan_holmes

@zhaop: I did indeed register to reply to you - and I'm glad I did, because it's working perfectly now!
After applying your patch it compiled and linked flawlessly (apart from all the clang warnings, of course - not that they matter). I also was able to make a bundle with ('make bundle_dist') and I can verify that it does work on a virgin Mac, which I guess means that distributing Mac binaries for experimental is a possibility.

Just for the record I didn't bother with the OpenGL backend, I just compiled it with SDL2.
For the supporting files I downloaded James' pak128.Britain-Ex complete package and deleted all the Windows executables and libraries. I then added the music and themes folders from the Simutrans-standard distribution for Mac. I doubt that the music folder is important for running the app but it would not start without the themes folder.

Thanks for all your help, everyone.

P.S. - it was somewhat comforting to open up simutrans and see 'railway' as opposed to 'railroad'!

jamespetts

#10
Zhaop - Splendid - thank you. I have now applied your patch and updated this to Github. Edit: May I ask what your username is on Github so that I can watch your repository for future patches, if any?

Ivan - I quite agree about the importance of language. These subtle things do make a difference.
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.

zhaop

Thank you both!

My github username is exactly as one might expect :) though my repo is directly forked off Standard.

I am trying to test networking. bridgewater-brunel.me.uk is not responding to queries; are any other experimental servers online?
I'm working on an AI for Simutrans that can make lots of money, and I'm currently learning the squirrel API for AI players.
https://github.com/zhaop/simutrans/tree/marmot

Vladki

Try server.exp.simutrans.com. check the web at the same adress for exact version it is running

zhaop

It works! Without any changes, I was able to connect to server.exp.simutrans.com, build two railway tiles, restart simutrans, reconnect, and they were still there.
I'm working on an AI for Simutrans that can make lots of money, and I'm currently learning the squirrel API for AI players.
https://github.com/zhaop/simutrans/tree/marmot

Vladki

Feel free to test it thoroughly. I get frequent desyncs (especially in depot), but they may be due to my home connection being slow.