How to setup boost for cygwin in Win XP

Boost is a super powerful and multi-platform C++ library. I always want to make use of this powerful tool. Here is the experience I had on how to install it for a Win XP box with cygwin:

1. the right instruction page to follow: Getting Started on Unix Variants (
2. which package to download: the source code package, e.g., from (, the version I downloaded was:

3. how to build: follow Section 5.1 of the instruction page “Getting Started on Unix Variants”

3.1 cd path/to/boost_1_41_0
3.2 ./ –prefix=/path/to/installation
3.3 ./bjam
3.4 ./bjam install

4. in /path/to/installation there will be 3 folders generated: bin, include, lib

5. copy these 3 folders to /usr/local/ (this is the local folder for the user installed packages instead of the standard cygwin packages)

6. build the test c++ program with linking to boost library regex
6.1 sample cpp file:


int main()
std::string line;
boost::regex pat( “^Subject: (Re: |Aw: )*(.*)” );

while (std::cin)
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;

6.2 sample makefile

CPP = g++
OFLAG = -Wall -o
LFLAG = -l
LIBDIR = /usr/local/lib/
INCLUDEDIR = /usr/local/include/
DEBUG = no

.SUFFIXES: .exe .cpp
    $(CPP) $(OFLAG) $@ $<

main.exe: boost.cpp
    $(CPP) $(IFLAG) $(INCLUDEDIR) $(OFLAG) boost.exe boost.cpp $(LIBFLAG)$(LIBDIR) $(LFLAG)libboost_regex

7. build the cpp file

8. create the test file to test the regexp functionality used in the above boost.cpp: save the following to test.txt

To: George Shmidlap
From: Rita Marlowe
Subject: Will Success Spoil Rock Hunter?

See subject.

8. test the boost.exe by

test.txt > ./boost.exe

9. the results shows successfully:  Will Success Spoil Rock Hunter?

Key point:

1. find the good instruction to follow

2. copy the include, bin, lib folders into the right path: /usr/local/

3. write the makefile correctly (setup good parameters for the compiler gcc)


7 thoughts on “How to setup boost for cygwin in Win XP

  1. Thanks! I was trying a custom build with the UNIX variant instructions from the Boost Getting Started Guide, but bjam.exe access permissions were insufficient to create any files. With these instructions, it’s now going. Thanks again.

  2. Attempting a cygwin compilation of boost on my windows xp machine. Did not have the same luck, working with version 1_43_0. Essentially fails in the first step of running the script, with the bootstrap.log showing errors such as the following:

    execunix.c:17:26: sys/resource.h: No such file or directory
    execunix.c:18:23: sys/times.h: No such file or directory
    execunix.c:19:22: sys/wait.h: No such file or directory
    execunix.c:27:23: sys/times.h: No such file or directory

    The files do exist in the /cygdrive/c/cygwin/usr/include/sys directory. I updated the PATH env variable to include the path to this directory, but with no luck. Is there a way that I can trigger the script to use the -I/cygdrive/c/cygwin/usr/include with the gcc compiler, or another workaround to make the build script see the path. Thanks.

  3. Okay, the problem was resolved by adding the /cygdrive/c/cygwin/bin to the very front of the PATH env variable, to ensure that the correct gcc compiler is used by the script.

    • Ok, I resoved it, but not sure why I had to put TWo TABs instead of one on lines 13,14 and 17. Now I am stuck again, cause the compiler does not like empty INCLUDE statements. Any help will be appreciated!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s