Wednesday, August 03, 2011

Warming up for Windows

Well I gave a little effort toward preparing to write a Windows version of my book today.  I wanted to keep it simple and use yasm, gcc and gdb.  Then the Windows book would be very easy to write.  Reality reared its ugly head when I stumbled into Windows territory.

I first tried installing Mingw and MSYS because I knew that Mingw has a 64 bit compiler.  I tried numerous times but never got a hello world program in C to compile.  I also had to install PKZip just to unpack one of the 2 zip files.  It was not looking good for describing in a Windows book how to install the tools.  It was looking impossible for me to do, although I am sure that it can be done and I would eventually stumble upon the secret.



Next I tried to use Mingw from within Cygwin.  Cygwin is easy to install and Mingw sounds easy from the stuff I read.  After several attempts I discovered that Cygwin has included a 64 bit version of Mingw as part of its collection of software.  My experience has been quite positive with Cygwin - things just work.  Well it took a while to figure out that I was supposed to use x86_64-mingw32-gcc as the name of the compiler and I thought it was going to be clean sailing after that.  I never got my hello world program to link.  I could generate a 64 bit assembly file so I knew I was on the right track.  But I never got past the unresolved symbol __chkstk_ms.  Google generally finds all this stuff pretty nicely, but was no help on this problem.  I was about ready for some ideas, so I posted my dilemma on Google+.

Glover George suggested that I use the free Microsoft Visual C++ Express.  I checked and apparently you can install the Windows Software Development Kit and then build 64 bit programs in Visual Studio.  After roughly 1 hour of confusion I produced a 64 bit hello world program.  I printed an address with %p format and printed sizeof(char *) just to make myself happy.  The character pointer was indeed 8 bytes!

So I guess I'll make the most of what Windows has to offer in this case.  Most likely the Windows users will be happier using Visual Studio than MSYS or Cygwin, though I would have been tickled pink to use either one.  There would be so little to learn.  Now I know that I could have figured the problems with MSYS and Cygwin out, but I am not too sure that I would have enjoyed explaining to people how to cope with the problems I had.  I think I can explain how to install the Microsoft tools quite well.  I might even like the Intellisense.

The bottom line is that a Windows version of the book will be significantly different.  I am happy that Microsoft offers a free solution.  Of course I haven't done the actual assembly code yet.  I think masm is on my Windows virtual machine at this point and I can cope with writing to the Windows standard.

The issue is settled enough for now.  I need to return to producing slides again.  9 chapters to go.

No comments: