views:

1930

answers:

4

This shoud be a simple problem for users more advanced than I am. :-) How do I use the boost library with cygwin on windows?

I am programing with g++ using cygwin on a winxp machine. I need modified Bessel functions of the second order, so I downloaded the latest version of the boost library and installed it in 'c:\cygwin\lib\boost_ 1_ 38_0\' folder.

I am trying to run the "example.cpp" program from the "getting started" section of their website: http://www.boost.org/doc/libs/1_35_0/more/getting_started/unix-variants.html

I am compiling from the directory where I created the example file using a simple Bash shell command line: 'g++ -Wall example.cpp'

I keep getting the message: "boost/lambda/lambda.hpp: no such file or directory"

I tried every possible combination of -L, -l, -I options in the command line to include the directory, to no avail. Also tried to add the folder in the PATH line of my windows system.

How do I link to the /boost directory and ALSO to all subdirectories? The header file 'lambda.hpp' is calling other header files in subdirectories.

+2  A: 

You're probably not that familiar with C++ yet? It seems you are confusing terms.

C++ programs are built in two steps: compiling and linking. In the first step, each source file (typically called .cpp) is handled individually. Each .cpp file usually uses multiple headers, so the compiler first inserts those - literally. That's why it's called #include.

In the second step, the linker takes all the compiled .cpp files together and builds your final program. Some of those compiled .cpp's might have been bundled together before, in which the bundle is called a library.

Boost is a collection of headers and .cpp files. So, both compiler and linker might need to find the Boost directories. From your error message, it's clear that the compiler step is the problem. The linker does not need headers anymore.

The compiler will see the #include <boost/lambda/lambda.hpp> instuction. That means it needs to know where that first-level boost directory is found. I would guess at this point that the path would be /lib/boost_ 1_ 38_0/include (there's always the find / -name lambda.hpp shotgun appraoch)

MSalters
+1  A: 

If you are not utterly wedded to cygwin, you should take a look at http://nuwen.net/mingw.html which gives you a complete MinGW C++ installation with all the libraries (such as Boost) set up for you.

Edit: I should make it clear you can use this MinGW installation in addition to Cygwin, not as a replacement. Just make sure the MinGW bin directory appears in your PATH before the Cygwin one.

anon
+1  A: 

I think you need -I /lib/boost_1_38_0 - although that's a pretty unusual place to put it. You'll have to let us know how you installed it, did you just unzip it in the location you said, or did you run the makefiles? I assume that since you gave a windows path you didn't install it within cygwin - which you probably should do. The instructions in the getting started guide for unix should help - although don't download a prebuilt bjam - it needs to be built with cygwin.

But if you're not very familiar with cygwin (or unix in general) I think you might find it easier to use a native windows tool - as in Neil Butterworth's answer.

Daniel James
+1  A: 

Thank you all for the information, it's a nice introduction to the use of libraries with cygwin. Daniel was right. While any variation gives an error, the following line (using caps i) does the trick:

g++ -Wall -I /cygdrive/c/cygwin/lib/boost_1_38_0/ example.cpp -o example

I will also check MinGW in the next few days.

p.s. I simply downloaded and unzipped boost in that folder, but since I am only using header files I probably won't need to compile with cygwin. [The boost version included with cygwin was 1.33, which does not seem to have Bessel functions.]