Installing MinGW and Boost on Windows XP
Friday November 23, 2012 14:40:17

MinGW is the premiere free non-Microsoft compiler for Windows. Even if you're primarily using Microsoft's compiler, compiling with MinGW, which is based on GCC, can give you a great head start to making your code compile with Unix. Additionally, if you want to use C++11 features, you can forget about doing it from a Windows XP box using a Microsoft compiler. Their cool new tools will compile to Windows XP, but can only be used on Windows 7 and up.

Installing MinGW it is fall off a log simple, but as I'm doing it on my old netbook right now I thought I'd document the process.

First, visiti the getting started page on MinGW's official website and download and run mingw-get-inst (you'll see it linked in the first few steps). Select “Download the latest repository catalogues” during the installation. Keep the default directory of C:\MinGW (the short path and lack of spaces helps with some tools). You can also select various compilers during the graphical installer, but don't, to relish the wonderful experience of installing these components from the command line.

Now add “C:\MinGW\bin” to the path.

Now install the following:

mingw-get install gcc
mingw-get install g++
mingw-get install mingw32-make

Working with Boost

The best way to work with Boost is to download the code and compile the libraries yourself. It's not easy, but controlling it yourself can offer insight into how these libraries are created and an appreciation for how portable it is.

Boost uses a special tool called Boost Build. You can think of this as an extremely flexible Make- once you've created your build script, you can build multiple configurations. For example, you can create a release version using Microsoft Visual C++ by invoking Boost Build one way, and then create a debug version with Gcc by invoking it another. Given that so much of C++ (and C) centers around how you build your code, it's nice that Boost Build abstracts this decision away from you until the end.

When you compile Boost itself, you need to be aware though that some options aren't configurable. One is whether or not you use the C++11 extensions for Gcc- Boost Build currently is not aware of this feature, so you need to remember it yourself. If you compile Boost for GCC without the C++11 flags set, it won't work with anything you compile using the C++ flags. So however you choose to use GCC, be consistent!

I recommend you use the GNU extensions because it works a little better with the Boost libraries. This involves passing the argument “-std=gnu++11” to the gcc compiler.

Building Boost

Download Boost from the official site. I have a program for all my tools, which I creatively named “C:\Tools”. Under this, I have a directory named “Boost”, and under that there's directories for every version of Boost I've downloaded.

I'm downloading Boost 1.52, so it's going to live in C:\Tools\Boost\boost_1_52_0.

Set the environment variable BOOST_ROOT to this path (again, ]I use a batch file to set up all these environment variables to avoid polluting the path). That's because Boost Build needs to have this set to work properly.

Now, in a command prompt enter that directory and type the following:

bootstrap.bat gcc
b2 --toolset=gcc cxxflags=-std=gnu++11 --build-type=complete stage cxxflags="-include cmath "

Again, gnu++11 is to make sure you build Boost with the C++11 features plus certain Gnu compiler extensions for maximum compatibility with Boost. The “-include cmath” works around a current issue building parts of Boost Python.

At this point go defrost a turkey because building Boost takes forever.

Once it's finished, congratulations! You can now take advantage of Boost in your programs.



Ken's ending from Street Fighter II as seen on Amiga
Monday November 5, 2012 03:25:21

This version of Street Fighter was understandably missing a few things, but the sprite work for Ken's fiance Lisa had to have been done by one of the developers as a joke (skip to 18:17).



Introducing Macaroni for C++
Monday October 1, 2012 00:28:20

It's with great pride and trepidation that I announce a project I've been working on for the past four years.

It's finally reached the point where I think it might be usable to people other than myself, so without further adieu I present “Macaroni for C++,” a sort of compiler for C++ that attempts to make working with C++ easier and more enjoyable.

Find out more here.



Intro to the Beginning of Getting Started on Windows
Sunday September 30, 2012 17:53:21

This blog post is intended to guide you through setting up a limited dev environment in Windows. The goal is to get around Windows annoyances and create a decent command line environment.

I'll be using Windows XP, since I have a spare license and can put a pristine install on a VM and can be assured the what I'm writing here is legit.

Change folder view options.
Right click on the Start bar, and select “Explore.” When the Explorer window pops up, click “Tools” then “Folder Options.” Select the “View” tab.
Check “Display the contents of system folders.”, “Show hidden files and folders.” Uncheck “Hide extensions for known file types” and “Hide protected operating system files (Recommended)” (click “Yes” to the popup). You may also want to uncheck “Remember each folder's view settings.” Finally, click Apply, then Ok.

Install Launchy.
Now, open up a internet browser (hopefully not IE), then download and install Launchy. Launchy lets you leave the Start Bar behind and open programs and folders by hitting ALT+Space then searching for them by name (it's why I'm incredulous when so-called power users write articles complaining about Windows 8 abandoning the Start Bar). Be sure to donate to Launchy if it helps you out!

Install Sublime Text 2.
Sublime Text is an awesome text editor that works on Windows, OSX, and Linux. Download it from this link and install it. Note that Sublime Text costs money, but one license is only $60 and applies to any computer you use which is awesome. You can try it out for free as long as you like, but if you use it forever without paying that'd make you a bad person.

Create a tools directory.
Pulling down a Windows Installer and letting it go nuts on your system is OK for some things but in general is a practice that 1. won't work for all tools and 2. isn't a good way to understand how the programs you use work. So my practice is to create a “Tools” directory which has all the stuff I use. An advantage to doing this is I can move the Tools directory to another machine if I need.

Create a new directory named “Tools” wherever. I'm going to assume it lives at “C:\Tools”.

Install Notepad2.
As nice as Sublime Text is, I also like to have use a different, single file editor at times to jot stuff down or open single files from Windows Explorer and Windows Notepad doesn't cut . Thankfully its freeware sequel is much nicer.

Download Notepad2 here. You can use the installer or not, it doesn't matter. However, it replaces the standard notepad, so lets try pulling down the non-installer version, which is a zip file. Open the zip file, then open a new Explorer window at the C:\Tools directory, create a folder named “Notepad2”, and dump the contents of the Zip file to it.

Now we're going to add Notepad2 to the “Send To” menu that appears when you right-click a file in Explorer. Open a new Explorer window, and enter the SendTo folder as explained here (for me it's located at C:\Documents and Settings\Tim\SendTo). Now, in the Explorer window with Notepad2 right click Notepad2.exe and select “Create Shortcut.” Move this shortcut into the SendTo folder and rename it to “Notepad2”.

At this point, Notepad2 will appear in the SendTo menu when you write click a file. This allows you quickly investigate the contents of a text file.

Create a batch file.
If you've ever had to change an environment variable in Windows, you'll probably agree that its a hellish experience and uses one of Microsoft's patented “impossible to resize even though all the critical contents can't be seen at once” windows.

That's OK though, because despite what most PHP installation tutorials tell you changing environment variables (especially PATH) globally is really gross and can destabilize your system.

Unix systems normally have a file called “bash.rc” or something similar which is executed every time a terminal is started. This is a great place to add environment variables and do other setup things. We're going to emulate that functionality in Windows by creating a batch file that'll execute each time we start a command prompt.

Enter C:\Tools\ and create a directory called “CmdTools”. Write click and select “New… Text Document.” Now right click the new file, select “Rename” and change the name to “DevStartup.bat”. Right click on it again, then select “Send To … NotePad2.”

Enter the following:

@ECHO OFF
REM SETLOCAL ENABLEDELAYEDEXPANSION
SET TOOLS_ROOT=C:\Tools
SET PATH=%PATH%;%TOOLS_ROOT%\CmdTools
ECHO Dev Environment

REM  Hard to see but there is indeed a lot of space on this next line
SET A_LOT_OF_SPACE=

REM Add some stuff to the path.
CALL :AddPath NOTEPAD2       "%TOOLS_ROOT%\Notepad2"

GOTO THE_END

REM Put subroutines and other stuff here.
:AddPath
SET TOOL_DIRECTORY_NAME=%1
SET TOOL_DIRECTORY=%2
REM - Strip quotes
SET TOOL_DIRECTORY=%TOOL_DIRECTORY:"=%
SET         FOUND=""
SET %TOOL_DIRECTORY_NAME%=%TOOL_DIRECTORY%

IF NOT EXIST "%TOOL_DIRECTORY%" GOTO NotFound
PATH=%PATH%;%TOOL_DIRECTORY%
SET FOUND=
GOTO PrintInfo
:NotFound
SET FOUND=MISSING
:PrintInfo
REM @ECHO %ELEMENT_NAME% == %ELEMENT_VALUE%

SET COL1=%A_LOT_OF_SPACE%%FOUND%
SET COL2=%A_LOT_OF_SPACE%%TOOL_DIRECTORY_NAME%
ECHO %COL1:~-7% %COL2:~-15% : %TOOL_DIRECTORY%
GOTO:EOF

:THE_END
REM ENDLOCAL
@ECHO ON

One important note: the line “SET A_LOT_OF_SPACE=” needs to have a bunch of spaces after it (like more than 80). As the comment implies there’s no good way (I could find in the two days I was interested in writing my batch file originally) to create a string with some set number of characters in it other than to just type a bunch of spaces after the equals.

Create a command line shortcut.
Open up C:\Tools in Windows Explorer, then right click somewhere and select “New Shortcut.” This will bring up a Wizard. For location, use:

C:\Windows\System32\Cmd.exe

Name can be anything I guess. I used “Dev Command Prompt”. Click Finish.

Right click the new shortcut and select properties.

For target, set this:

%comspec% /k ""C:\Tools\CmdTools\DevStartup.bat"" x86

For start in, put the name of whatever directory you most prominently work in. I personally have all of my work in a single root directory which is what I put here.

Now click “Layout”. In “Screen Buffer size”, the default number of lines is 300 which is absurd. You'll want something much higher. 2500 is probably good enough.

Width starts off as “80.” I personally try to make all of my work 80 columns, but the output of most tools is not so conservative so I go with 120 here. Enter that value for “Width” in both spots.

Click Apply to save the changes. Double click on the shortcut and you should see the following:

CMD PROMPT
                 NOTEPAD2 : C:\Tools\Notepad2
C:\Work>

Type “Notepad2” and you'll see Notepad2 pop up, even though we didn't use the installer.

Make Dev Command Prompt accessible from Launchy.

Right click the short cut and select copy.

Now click the Start Bar, and select All Programs, then right click Accessories and select Open. Paste the shortcut into that folder.

Hit Alt + Space to bring up Launchy. Right click on the little space ship icon to the right of the text box, and select “Rebuild Catalog.”

Now when you type “Dev Command Prompt” into Launchy it should open the new terminal.

Adding other programs.

The batch file puts the directory “C:\Tools\Notepad2” on the path, allowing you to type Notepad2 to launch it.

To add other tools to the path, add lines similar to the following:

CALL :AddPath NOTEPAD2       "%TOOLS_ROOT%\Notepad2"

For example, if you want to put MinGW on your path, you'd probably write this:

CALL :AddPath MINGW           "C:\MinGW\bin"

The nice thing is the batch file will show you just how populated your PATH environment variable is.

This batch file is also a good place to stick other vars. For example, lets say you're using the Clojure programming tool Leiningen and need to set the var “LEIN_JAR.” Just put the following line next to all the calls to “AddPath:”

SET LEIN_JAR=C:\Users\Tim\Tools\Local\Leiningen\leiningen-2.0.0-preview10-standalone.jar

At this point you should be ready to go. If you want more information on how the batch file works you can read this post from my old blog where I went into greater detail on it.





<---2012-12-27 19:47:09 history 2012-09-30 16:31:41--->



-All material © 2007 Tim Simpson unless otherwise noted-