Monday 17 May 2010

How to Build Polyworld for Windows


How to Build Polyworld for Windows
  1. Get Qt and MinGW

    Download qt-sdk-win-opensource-2010.02.1.exe
    Install to d:\work\tools\qt

  2. Get GSL for Windows

    Download gsl-1.8-bin.zip and gsl-1.8-lib.zip files
    Extract to d:\work\tools\gnu32

  3. Get CVS

    Download cvs-1-11-22.zip
    Extract to d:\work\tools\cvs

  4. Get Boost

    Download boost_1_43_0.zip
    Extract to d:\work\tools\boost

  5. Start the Qt Command Prompt

    start > all programs > qt sdk by nokia v2010.02.1 (open source) > qt command prompt

  6. Set up your path

    path=%path%;d:\work\tools\gnuwin32\bin;d:\work\tools\cvs

  7. Download polyworld

    cvs -d:pserver:anonymous@polyworld.cvs.sf.net:/cvsroot/polyworld checkout -P polyworld
    Copy to d:\work\polyworld

  8. Get a Project File and a World File

    Dowload polyworld-modified.zip
    Extract to d:\work\polyworld-modified
    Copy d:\work\polyworld-modified\polyworld.pro to d:\work\polyworld
    Copy d:\work\polyworld-modified\debug\worldfile to d:\work\polyworld\debug

  9. Genrate a Makefile

    Go to d:\work\polyworld
    Double check that all the directories in polyworld.pro are correct for you.
    qmake

  10. Edit the souce code

    See instructions below

  11. Build

    Go to d:\work\polyworld
    mingw32-make
Edit the source code
  1. Some header files are in a different place for MinGW

    Look for the files in d:\work\tools\qt\2010.02.1\mingw

  2. Some header files are not available for MinGW

    Put a #ifdef linux and #endif around them.

  3. Some functions are not available for MinGW

    MinGW does not have drand48().
    Instead use double( rand() ) / double( RAND_MAX )

    MinGW does not have alloca().
    Instead use boost shared arrays

    For the rest, put a #ifdef linux and #endif around them.
    There are some big chunks where you'll have to do this but you won't affect the simulation too much.

    There are some functions for file writing that won't work because Polyworld uses a few commands only available on Linux and Mac. Use the worldfile in polyworld-modified.zip to disable most of them.

  4. Some functions will cause a crash

    There are a few lines in the genome::crossover() that will cause a crash.

  5. There are a few more small changes you'll need to make but I hope this guide has helped you with most of the big ones.
Notes
  • If you have trouble modifying the code, I've included the modifications in polyworld-modified.zip

  • If you have trouble building the code, I've included polyworld.exe and all of the dependencies in polyworld-modified.zip

  • Use the dynamic link libraries in d:\work\tools\qt\2010.02.1\qt\bin and not d:\work\tools\qt\2010.02.1\bin
References
  • http://www.beanblossom.in.us/larryy/BuildingPolyworld.html
  • http://wiki.yak.net/634
  • http://wiki.yak.net/630

22 comments:

  1. why don't they just build this and put this in the section that says windows seriosly

    ReplyDelete
  2. Hi Anonymous,

    I hope you've had good luck building Polyworld.

    The libraries that Polyworld uses has progressed immensely. This has made it easier to port to Windows.

    ReplyDelete
  3. how do you edit the source code? I don't understand it at all. what coding language is it? polyworld keeps crashing.
    When I execute the "mingw32-make" command in qt it says: "mingw32-make: *** [debug] error 2"

    ReplyDelete
  4. Hi Anonymous,

    You can edit the source code with most text editors. I use emacs but I recommend Notepad++ for most people.

    The source code is in C++.

    I'm not sure why Polyworld is crashing for you. Are you trying to run the version I built in polyworld-modified.zip? You have to run it from the Qt command prompt with modifications to the path I described above so that Polyworld can find the dynamic link libraries it needs.

    Are you calling mingw32-make to build Qt or Polyworld? You don't need to build Qt because it is already built. You may need to generate a Makefile for Polyworld using qmake as I've described above.

    Hang in there. It is usually only a few small things that get in the way. Please let me know if you have further questions.

    ReplyDelete
  5. Ok, I've downloaded cvs sources and built them under VC2005. It seems to run fine, except for slow window reaction. Hmm.. What do I do with it now? Should I upload binaries somewhere?

    ReplyDelete
  6. Hi Anonymous,

    I'm glad that you were able to build and run the Polyworld code.

    The version you've got is a small modification of Larry Yaegar's code to work on Windows.

    I've been working on a version of Yaegar's code for a while now and it's quite different. I'll be uploading the binaries for that soon. I'm currently integrating Bullet code for physics and OGRE code for graphics into my version.

    You options depend on your intentions. What are you intending to do with the code? Make your own modifications? It would be great if you also had a place where you could upload your binaries and write about what you're doing.

    ReplyDelete
  7. Thanks for the instructions, Binh. I was able
    to build from a new cvs version for windows except for the worldfile loading, which I used the old code for, as you also did.

    ReplyDelete
  8. You're welcomed Tom. I hope you get a lot out of working with Polyworld as I have.

    ReplyDelete
  9. How exactly do you go about linking the dynamic link libraries?

    ReplyDelete
  10. Hi Anonymous,

    You don't need to do anything extra to use the dynamic link libraries. You include Qt header files in your code, compile, and link.

    At run time your program will look through the paths you specified for the dynamic link libraries.

    ReplyDelete
  11. YES! With this, I will finally be able to show that I am AWESOME INCARNATE! Ty Binh... Any problems I'll let you know. XD

    ReplyDelete
  12. Well...
    Didn't think I'd run into a problem this fast, but it appears I don't have d:\work\tools\qt, nor do I know how to make it. So, how do I make it?

    ReplyDelete
  13. Hi Archulous,

    Always good to hear from more people using Polyworld.

    You can get d:\work\tools\qt by specifying to Qt that directory during the installation process.

    Or you can create those directories yourself using Windows Explorer and then move Qt there.

    Moving Qt is a little tricky. I've written up two guides to help you do this.

    http://tb-nguyen.blogspot.com/2010/10/how-to-move-qt-install-library.html

    http://tb-nguyen.blogspot.com/2011/01/how-to-move-qt-install-library-version.html

    Best of luck and let me know how you go.

    ReplyDelete
  14. I'm a little confused about editing the source code. I'm not sure which files I need to change, hopefully not all of those files in qt\mingw\include, but if that's what it takes, I'll probably do it. Thanks for the help.

    ReplyDelete
  15. Hi Anonymous (7/11/11),

    You can use the error messages you get when you compile and run the program to guide your editing of the source code.

    All the error messages are straightforward. Good luck!

    ReplyDelete
  16. Hello,
    I have little to no experience with C++. I think I have done pretty well even with that slight handicap, but I am stuck with a couple of things. For the first one I have looked around on the internet, but that didn't help. I can't figure out what's wrong except that about everything is "#ifdef"ed in the "#define"
    Here's what the prompt gives me:

    app\simulation.cp: in member function 'void TSimulation::init{const char*)*':
    app\simulation.cp:1503: error: expected primary-expression before '}' token
    app\simuation.cp:1503: error: expected ';' before '}' token

    I'm also not sure whether I need to do anything about warnings similar to this:

    utils/Queue.h:131: warning: ignoring #pragma omp atomic

    Thank you for your help.

    ReplyDelete
  17. just turn it into a exe file for the benefit of all enthusiasts!!!!!!!!!

    ReplyDelete
    Replies
    1. I'm thinking about regularly releasing executables of the simulation I've been working on.

      Delete
  18. I don't think people understand why releasing an .exe is a bad idea... do you people even know why you need to edit the source code every so often and how hard would be to code an executable that lets you mess with -everything- in the source?
    I'd prefer if that person worked on whatever important he has working on atm rather than making executables for every person that just wants to stare at polygons evolving. When the program gets to 100% completion you can then ask for an executable and mess with it as much as you like. Till then take the source and help work on it.

    ReplyDelete
  19. Binh, thank you very much for all your hard work! After a bit of fussing around, I was able to build this using Qt 5.x on windows. If anyone is interested in checking out the codebase I am working on, here is a link to the source on github.

    https://github.com/rockhowse/polyworld-modified

    ReplyDelete
    Replies
    1. Hey rockhowse,

      You're welcomed and well done on getting it to work with Qt. I've always found Qt challenging to use.

      Delete
    2. And thank you for fixing up the code and putting it up on github :)

      Delete