Un-removable folders: continued

Pages: 12
ok, so, I came to a boost 'tutorial' website, with the intention of finding the functions which are specific to boost and came accross this turorial site for Boost library. It had a test program on it so I thought i would test out the new library with it:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

int main()
{
    using namespace boost::lambda;
    typedef std::istream_iterator<int> in;

    std::for_each(
        in(std::cin), in(), std::cout << (_1 * 3) << " " );
}


When I tried to compile the program:

main.cpp|1|error: boost/lambda/lambda.hpp: No such file or directory|


So, it can't find the library... Can someone tell me how I can set this up?
You need to add the new MinGW include directory to the list of directories Code::Blocks tells the compiler to search for headers in. Probably "C:/mingw/include" or something like that.
alright I'll try that! ty

EDIT1:

It didn't work :(

I have the GCC compiler working. I just need to figure out how to get it to locate the Boost Include files.
Last edited on
I have nuwen mingw as well, and boost headers are installed in c:\MinGW\include\boost. As ModShop said you need to add mingw\include to the include directories in codeblocks.
I have tried adding that directory useing the 'toolchain executables: additional paths' tab and it didn't work. Can you please explain how/what menu I should use?

I have not added a 3rd party library before, so I would need a full explanation of how to do it.
Last edited on
Create a project. Add all of your files to it. Right click on the project name in the Management window (on the left). Click on "Build options". Click on the "Search directories" tab. Click on the "Add" button. Type the directory name (or use the "..." button to find it with Windows Explorer).
So, you already have your code compiling, but you still can't use boost libraries...

There isn't really anything different you need to do, but I'll show you the default values.

C:\MinGW\bin\g++.exe - Location of the C++ Compiler (this works)
C:\MinGW\include\ - Location of the standard C++ header files (this works)
C:\MinGW\include\boost\ - Location of the boost header files (this doesn't work)

Since the include directories already work, you shouldn't need to do anything specific. However, I would check to make sure that the boost folder exists in the include directory and that there are header files in there.

Try this sample code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <string>
#include <iostream>
#include <boost/foreach.hpp>

int main()
{
    std::string hello( "Hello, world!" );

    BOOST_FOREACH( char ch, hello )
    {
        std::cout << ch;
    }

    return 0;
}


Before compiling it, make sure this file exists:
C:\MinGW\include\boost\foreach.hpp
If you can locate it (in that exact location), than the code should compile fine. If you locate it and you can't compile it, post the error message here.

Reminder: When using the boost header files, make sure you signify the boost folder before the header file name. This allows the compiler to find the file.

Additional Note: If you use a non header only library (check the boost documentation on their website), you need to include the library that corresponds with the header file. For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//
// timer.cpp
// ~~~~~~~~~
//
// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

int main()
{
  boost::asio::io_service io;

  boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
  t.wait();

  std::cout << "Hello, world!\n";

  return 0;
}


boost.asio requires the use of libaries. Since (by default) the C:\MinGW\lib\ directory is already included in the search directories, you simple need to edit the project build options to include the specific library. Simply go to the project's Build Options...(right click on the project name in the project manager and select Build Options...) and then click on the name of the project on the left side of the new window. This sets defaults for both Debug and Release. The next step is to select the Linker Settings tab in the center of the screen. Simply click add then type in the name of the library to be included (minus the lib prefix and the .a extension).

I don't think the recent code has any dependencies upon any libraries, but if you try to compile it and get an error, report back here and post any error messages you get.

I hope this helps you out. Boost libraries are very powerful.
1. The Boost include files do exist (only about 9000 of them 0.o)

2. It is NOT using the minGW in the C:\ directory. When I installed Code::Blocks, I got the 'Code::Blocks + MinGW' package. So, MinGW is in the program folder if that makes any difference.

3. I copied and pasted your code, went to the compiler settings, under the toolchain executables tab, additional paths tab: I added the "C:\MinGW\include\boost" directory. I compiled the code and:

C:\Users\username\Desktop\C++\Boost test\main.cpp|3|error: boost/foreach.hpp: No such file or directory|
2. It is NOT using the minGW in the C:\ directory. When I installed Code::Blocks, I got the 'Code::Blocks + MinGW' package. So, MinGW is in the program folder if that makes any difference.


This is your issue then, You need to change the executable toolchain. It's possible that clicking the autodetect button when using the C::B + MinGW installer will cause it to select that version of MinGW each time you click that. What you need to do is open up the executable toolchain and modify this:

Compiler's installation directory: C:\MinGW

I don't have it currently installed on this computer (switched to Ubuntu last night =D ) so I can't verify the actual .exe names. Some of the Program Files might need to have their name changed. Additionally, remove all of the Additional Paths that you added in. That's only if you have your executables (that are used to compile) in separate folders.

We're closer to getting this done than you think =)
SWEET! It worked! Ty Volatile Pulse for all your help!

Now I will google for a site with Boost function descriptions so I can start using boost magic ;)
www.boost.org has every single function documented. It's a bit hard to read, but the directory functions are pretty easy to use.

Good luck and I'm glad everything is working for you now.
Topic archived. No new replies allowed.
Pages: 12