Compiling Stratagus on Mac OS X (10.8.2)

I loved playing Warcraft 2. I played it on DOSBox recently, but the fact that 640×480 is just plain ugly on my MPB these days made me look for alternatives.

And so I found Stratagus and Wargus.

With Stratagus as engine, Wargus as “MOD” and with the original Warcraft 2 CD you can re-live Warcraft 2 again on your machine.

On Windows you should be able to install this without any problems, installers are provided and these work just fine. However, on a Mac you might be in some hassle to get this working. In fact, there is no official support as none of the authors run a Mac. Basically this means people with Macs had to figure out how to do this. After some time of googling I got Stratagus compiling and working with a Wargus game I already created on Windows.

Fortunately someone at github already made a version that should work on Mac OS X. Combined with a tutorial I found elsewhere I got it to compile. I can play Wargus now on my Mac!

For completeness sake I have combined the steps I have taken (and also forked Stratagus) so you can use that version. Don’t credit me for making Stratagus compile on the Mac though, as I did not make the nescesary changes in the makefile or code.

Install Xcode (from App store) & Install command line tools from Xcode

in Xcode, go to preferences, tab "Downloads" -> " Components" -> Command Line Tools
  • – The command line tools should have installed git and svn for you, try them out:
hit "svn --version", and "git --version" in your terminal.
If they are not installed, you could install them via homebrew (brew install git && brew install svn) (after you installed Homebrew of course)

Install homebrew

ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go

Installing required dependencies

I have installed the following dependencies with homebrew like this:

brew install cmake libogg libvorbis theora libpng zlib libmikmod sqlite3 doxygen

Compile and build tolua

Go to your projects dir

git clone https://github.com/LuaDist/toluapp.git

cd toluapp

cmake -G "Unix Makefiles"

make && sudo make install

Git clone stratagus

Determine where you want to checkout stratagus, ie in your ~/projects, then:

git clone https://github.com/stefanhendriks/stratagus

Compile it

cd stratagus
mkdir build
cd build
cmake -G "Unix Makefiles" ..
make

Now you should be able to run a stratagus game. Since I already created Wargus by using Windows, I copied this over to my mac (and put it in ~/projects/Wargus). Then I ran stratagus as:

./stratagus -d ~/projects/wargus/

A known issue I have is that on startup the screen looks as if it is drawing with a weird offset (ie too much out of screen at the upper left). By simply changing resolution this goes away. Don’t know why yet, but since we have the code now and we can compile, we might as well try to fix it some day! 🙂

Personally I’d like to see a better AI for wargus, especially since I like to play Skirmish games.

I hope this guide helped you get it to work on your mac. Please share your experiences in the comments section.

Comments

  1. hi, hoped to see a working guide, but i ran into errors. any chance there will be a binary file for os x?

    1. Could you be more specific about the errors? I think it is possible to provide binaries, but you still would need the correct dependencies (I believe). If you want I could provide the frameworks that you normally would have compiled yourself? You could try them out and see if it works, although I would still encourage you to get it working via this guide, because you probably need this to work anyway for any further work you need to do 🙂

  2. Just a tip: Clang compiler does not worked for me. GNU GCC worked.

    Here (Mavericks 10.9.2) the build had not worked:
    $ cmake -G “Unix Makefiles” ..
    — The C compiler identification is Clang 5.0.0
    — The CXX compiler identification is Clang 5.0.0
    — Check for working C compiler: /usr/bin/cc
    (…)
    [ 9%] Building CXX object CMakeFiles/stratagus.dir/src/action/command.cpp.o
    [ 10%] Building CXX object CMakeFiles/stratagus.dir/src/animation/animation.cpp.o
    /Users/alanjds/src/git/stratagus__stefan/src/animation/animation.cpp:123:9: error: use of undeclared identifier ‘atoi’
    return atoi(parseint);
    ^
    (…)
    5 errors generated.

    Then I suspected that the Clang compiler had broken the build, and I gone for the GNU GCC:

    $ brew install homebrew/versions/gcc49
    (waited ~45 minutes for GCC to compile…)
    $ export CC=/usr/local/bin/gcc-4.9 CXX=/usr/local/bin/g++-4.9
    $ cmake -G “Unix Makefiles” ..
    — The C compiler identification is GNU 4.9.0
    — The CXX compiler identification is GNU 4.9.0
    — Check for working C compiler: /usr/local/bin/gcc-4.9
    (…)
    [ 9%] Building CXX object CMakeFiles/stratagus.dir/src/action/command.cpp.o
    [ 10%] Building CXX object CMakeFiles/stratagus.dir/src/animation/animation.cpp.o
    [ 10%] Building CXX object CMakeFiles/stratagus.dir/src/animation/animation_attack.cpp.o
    (…)
    [100%] Building CXX object CMakeFiles/stratagus.dir/tolua.cpp.o
    Linking CXX executable stratagus
    [100%] Built target stratagus

    It worked! Yay!!

      1. Another one: libpng already comes with XQuartz I guess, so it messed up trying to run after the compilation

        $ ./stratagus -d ~/Wargus/
        Stratagus V2.2.7, Copyright (c) 1998-2012 by The Stratagus Project and Pali Rohar
        (…)
        Compile options ZLIB BZ2LIB VORBIS THEORA MIKMOD OPENGL MAC
        (…)
        libpng warning: Application built with libpng-1.5.17 but running with 1.6.10
        Couldn’t allocate memory for PNG fileCan’t load the graphic `ui/fonts/game.png’

        So I had to unlink homebrew libpng and recompile to let it use system-wide libpng.

        $ ./stratagus -d ~/Wargus/
        Stratagus V2.2.7, Copyright (c) 1998-2012 by The Stratagus Project and Pali Rohar
        (…)
        Compile options ZLIB BZ2LIB VORBIS THEORA MIKMOD OPENGL MAC
        (…)
        Thanks for playing Stratagus.

  3. For some reason, toluapp won’t install on a mid-2009 MBP 13″ running OS X 10.8.5.

    I brewed gcc, lua, lua51 and all the dependencies listed above, but no dice…

    Which lua version should I use (I think this may be the source of my problems)?

    $ make && sudo make install
    [ 14%] Building C object CMakeFiles/toluapp_lib.dir/src/lib/tolua_map.c.o
    /Users/captainhennessey/toluapp/src/lib/tolua_map.c:266:2: warning: implicit declaration of function ‘lua_setfenv’ is
    invalid in C99 [-Wimplicit-function-declaration]
    lua_setfenv(L, -2);
    ^
    /Users/captainhennessey/toluapp/src/lib/tolua_map.c:274:2: warning: implicit declaration of function ‘lua_getfenv’ is
    invalid in C99 [-Wimplicit-function-declaration]
    lua_getfenv(L, -1);
    ^
    /Users/captainhennessey/toluapp/src/lib/tolua_map.c:398:58: warning: passing ‘const char *’ to parameter of type ‘char *’
    discards qualifiers [-Wincompatible-pointer-types]
    if (tolua_newmetatable(L,ctype) && tolua_newmetatable(L,type))
    ^~~~
    /Users/captainhennessey/toluapp/src/lib/tolua_map.c:28:52: note: passing argument to parameter ‘name’ here
    static int tolua_newmetatable (lua_State* L, char* name)
    ^
    /Users/captainhennessey/toluapp/src/lib/tolua_map.c:414:19: error: use of undeclared identifier ‘LUA_GLOBALSINDEX’
    lua_pushvalue(L,LUA_GLOBALSINDEX);
    ^
    /Users/captainhennessey/toluapp/src/lib/tolua_map.c:448:19: error: use of undeclared identifier ‘LUA_GLOBALSINDEX’
    lua_pushvalue(L,LUA_GLOBALSINDEX);
    ^
    3 warnings and 2 errors generated.
    make[2]: *** [CMakeFiles/toluapp_lib.dir/src/lib/tolua_map.c.o] Error 1
    make[1]: *** [CMakeFiles/toluapp_lib.dir/all] Error 2
    make: *** [all] Error 2

    1. I have Lua version:

      Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio

      I am unsure why you get these warnings. Perhaps some dependencies LUA depends on? Any luck so far?

    2. I’ve just tried this myself and it worked, although I have some warnings (Mac OS X 10.9.5). What I did:
      – git clone https://github.com/LuaDist/toluapp.git
      – cd toluapp
      – cmake -G “Unix Makefiles”, which outputs (for me):

      — The C compiler identification is Clang 6.0.0
      — Check for working C compiler: /usr/bin/cc
      — Check for working C compiler: /usr/bin/cc — works
      — Detecting C compiler ABI info
      — Detecting C compiler ABI info – done
      DIST_NAME: toluapp
      DIST_VERSION: 1.0.93
      DIST_LICENSE: as-is
      DIST_AUTHOR: Waldemar Celes, Ariel Manzur
      DIST_MAINTAINER: Peter Kapec
      DIST_URL: http://www.codenix.com/~tolua/
      DIST_DESC: tolua++ is an extension of toLua, a tool to integrate C/Cpp code with Lua.
      DIST_DEPENDS:
      — Found Lua: /usr/local/lib/liblua.dylib (found version “5.1.5”)
      — Configuring done
      — Generating done
      — Build files have been written to: /Users/shendriks/projects/toluapp

      And then:
      – make && sudo make install

      Which outputs:
      Scanning dependencies of target toluapp_lib
      [ 14%] Building C object CMakeFiles/toluapp_lib.dir/src/lib/tolua_event.c.o
      [ 28%] Building C object CMakeFiles/toluapp_lib.dir/src/lib/tolua_is.c.o
      /Users/shendriks/projects/toluapp/src/lib/tolua_is.c:119:58: warning: duplicate ‘const’ declaration specifier [-Wduplicate-decl-specifier]
      static int lua_isusertable (lua_State* L, int lo, const const char* type)
      ^
      1 warning generated.
      [ 42%] Building C object CMakeFiles/toluapp_lib.dir/src/lib/tolua_map.c.o
      /Users/shendriks/projects/toluapp/src/lib/tolua_map.c:398:58: warning: passing ‘const char *’ to parameter of type ‘char *’ discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
      if (tolua_newmetatable(L,ctype) && tolua_newmetatable(L,type))
      ^~~~
      /Users/shendriks/projects/toluapp/src/lib/tolua_map.c:28:52: note: passing argument to parameter ‘name’ here
      static int tolua_newmetatable (lua_State* L, char* name)
      ^
      1 warning generated.
      [ 57%] Building C object CMakeFiles/toluapp_lib.dir/src/lib/tolua_push.c.o
      [ 71%] Building C object CMakeFiles/toluapp_lib.dir/src/lib/tolua_to.c.o
      Linking C shared library libtoluapp.dylib
      [ 71%] Built target toluapp_lib
      Scanning dependencies of target toluapp
      [ 85%] Building C object CMakeFiles/toluapp.dir/src/bin/tolua.c.o
      [100%] Building C object CMakeFiles/toluapp.dir/src/bin/toluabind.c.o
      Linking C executable toluapp
      [100%] Built target toluapp
      Password:
      [ 71%] Built target toluapp_lib
      [100%] Built target toluapp
      Install the project…
      — Install configuration: “”
      — Installing: /usr/local/lib/libtoluapp.dylib
      — Installing: /usr/local/bin/toluapp
      — Installing: /usr/local/include/
      — Installing: /usr/local/include//tolua++.h
      — Installing: /usr/local/share/toluapp/README
      — Installing: /usr/local/share/toluapp/INSTALL
      — Installing: /usr/local/share/toluapp/doc/
      — Installing: /usr/local/share/toluapp/doc//index.html
      — Installing: /usr/local/share/toluapp/doc//tolua++.html
      — Installing: /usr/local/share/toluapp/doc//toluapp.gif

      Does this give you any clue?

      1. WOW. Spend a lot of time trying to build. This comment helped me a lot!
        Thanks! You are awesome!)

        1. Glad it helped you! Thx for your feedback. Anything you ran into with my post? Could it be improved?

          1. Right now i have problem with SDL. When i’m trying to build it, it runs to 97% and breaks on it. I was trying to re-install SDL library with brew – still no success. Maybe you know something bout it.
            Here is my log from terminal:

            [ 97%] Linking CXX executable stratagus
            ld: library not found for -lSDLmain
            clang: error: linker command failed with exit code 1 (use -v to see invocation)
            make[2]: *** [stratagus] Error 1
            make[1]: *** [CMakeFiles/stratagus.dir/all] Error 2
            make: *** [all] Error 2

          2. Also this log before:
            [ 95%] Building CXX object CMakeFiles/stratagus.dir/src/video/sprite.cpp.o
            [ 96%] Building CXX object CMakeFiles/stratagus.dir/src/video/video.cpp.o
            [ 96%] Building CXX object CMakeFiles/stratagus.dir/tolua.cpp.o

            Maybe toluapp is associated in some way

          3. Also after executing make second time – error appears earlier
            [ 0%] Built target genversion
            [ 1%] Built target png2stratagus
            Scanning dependencies of target stratagus
            [ 2%] Building CXX object CMakeFiles/stratagus.dir/src/action/actions.cpp.o
            [ 3%] Building CXX object CMakeFiles/stratagus.dir/src/game/game.cpp.o
            [ 4%] Building CXX object CMakeFiles/stratagus.dir/src/game/replay.cpp.o
            [ 4%] Building CXX object CMakeFiles/stratagus.dir/src/game/savegame.cpp.o
            [ 4%] Building CXX object CMakeFiles/stratagus.dir/src/map/map.cpp.o
            [ 5%] Building CXX object CMakeFiles/stratagus.dir/src/map/script_map.cpp.o
            [ 6%] Building CXX object CMakeFiles/stratagus.dir/src/network/net_message.cpp.o
            [ 6%] Building CXX object CMakeFiles/stratagus.dir/src/network/master.cpp.o
            [ 7%] Building CXX object CMakeFiles/stratagus.dir/src/network/netconnect.cpp.o
            [ 7%] Building CXX object CMakeFiles/stratagus.dir/src/stratagus/stratagus.cpp.o
            [ 8%] Linking CXX executable stratagus
            ld: library not found for -lSDLmain
            clang: error: linker command failed with exit code 1 (use -v to see invocation)
            make[2]: *** [stratagus] Error 1
            make[1]: *** [CMakeFiles/stratagus.dir/all] Error 2
            make: *** [all] Error 2

            But after i clear all files created by cmake, then execute cmake again – error appears one time at 97% and then as i mention before – at 8%

  4. Hi guys. Just thought I add my experience here. For a while I’ve wanted to compile Stratagus on the even rarer than OSX platform 10.5.8 PPC. I tried to follow the advice here as I have always got into trouble trying to compile it. In fact I had got it compiled for the even rarer AmigaOS4 PPC platform so was surprised when building on OSX, even it was on PPC, it always broke.

    I found some things that always tend to break. LibPNG and ToLua++. The after you deal with all of that SDL will break the linker and all your hard work will be made useless. In any case this has been my experience the last week really having a go of it. And I finally got it working!

    Unlike here, I started using Mac Ports for my dependencies, from using it with another project. I may check out Brew, as I found a PPC fork. And all Ports does here is download sources which to me is not ported. Anyway enough titter tat. 🙂

    First up. Getting toluapp to work. You may be tempted to compile a “modern” toluapp that is fixed for LUA 5.2/5.3+. Don’t. And here;s why. Stratagus depends on Lua51. If you compile a working toluapp with lua 5.2+ like I did it will break the Stratagus compile. I don’t know if Brew acts like Port but I told it to install toluapp and it assumed it needed lua which defaults to 5.2+. This is not correct, it’s not correct because Lua51 is perfectly fine to satisfy it and also because in the case of Port it is broken with Lua 5.2+ with a fix they haven’t released. So how on earth do you get toluapp working? I removed all lua versions installed except Lua51. With Lua51 active I then downloaded the “normal” toluapp as above and compiled it as so.,

    Now after that hurdle you may get stuck on SDL. Well I did. In my case I had a broken SDL in my /Library/Frameworks I put in there to get some, emulator working. I found it was broken and killed the main() routine in an attempt to convert it to SDL_main() in a header file. This will break the linker with a cryptic crt object error. In my case the fix was to delete the framework so the working SDL was detected.

    So that that done. I reran CMake and make again. Which compiled it all again. Only takes about 15 minutes on my 1.5Ghz G4 IIRC. And then suddenly it works! :-O

    Hmm, seems abut slow. Only needs 300Mhz CPU? Yeah right! 😛

    I wonder also, I tried to build as static which had no effect ,can this be done? Perhaps locate an app builder would be best. I also saw some message about how Quartz should should be used., easy to activate? And also, OpenGL ES, I see a lot of messages about this. Would this be better then normal OpenGL if OSX has it?

    Thanks for your blog. It helped me. 🙂

  5. Glad to add my experience. I also used the Stratagus above to build a nice Wargus app with icon. All I need is the data files. Be nice if we have an installer for that. 🙂

  6. Sorry for posting without having the knowledge necessary, but I don’t know anything about MAC OS (I’m a windows user, yet at least have compiled stratagus for windows in the past). I wanted to know if for MAC do you get binaries that you can share with others?

    I ask because my mac-using friends run into lot of trouble trying to get wargus to work, and MAC isn’t officially supported by the devs as stated in the post above. So if binaries can be shared it would be useful for people like them!

    1. It depends on how the stuff is build and bundled. In this case the dependencies (libraries and other programs required to run the game) are separate from the game itself. Ideally you want to provide them with the game so others do not have to bother compiling those. (static binary I believe) I haven’t looked into that. So I won’t assume that it would just work if you would copy the stuff to your friends.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.