User forums > Help

Configuring Boost with Code::Blocks

(1/6) > >>

aaronds:
Hi,

I've never configured an external library with a C/C++ IDE before so this is all new to me. I'm looking to configure the Boost library with Code::Blocks (windows, MinGW) but I just can't get it working. I have built and installed the Boost library, I just need to configure it with my project. I have of course consulted the documentation but it appears to be some what out of date, as it uses Boost 1.42 (I'm using 1.47). The documentation talks about include and lib folders, neither of which are in my installation.

So far, I have set up a global variable in the IDE called "boost" that links to the base directory of the boost installation as the base field (under builtin fields) and links to the boost/ subdirectory as the include field. Within the build options for my project, under search directories, I have set the compiler directory to the boost subdirectory within the boost installation folder, while I have also set the linker directory to the stage folder.

However, I am aware that even if all that I have done so far is correct, I still need to add additional linker settings but I'm lost as to what to do here. From what I can make out in the documentation I need to link specific libraries (I'm trying to use the asio library within Boost), but I can't find anything relevent within my boost installation.

If anyone could tell me whether what I've done so far is correct or not and perhaps direct me on where I should go from here, I would be very appreciative.

Cheers

Alpha:
It sounds like you have done most everything correctly so far, but just in case, I will list out several steps.

Create the global variable boost with extract_dir as the base.  (This is C:\Libraries\boost_1_47_0 on my computer.)  The other fields do not need anything (except possibly lib; if you used a custom directory while building boost, put the path here).
Next (assuming you are starting a project, not adding to an existing one), create a new project (a console app should be fine; see this page if you need step-by-step instructions on that).
In this project, open Project->Build options... and ensure that the overall name of the project is selected in the left-hand column (for example, boost_test).  Switch to the Search directories tab and click Add (for the Compiler tab).  In the box, type $(#boost) and click OK.
Many features of boost do not require any libraries, (asio included).  Here is a list of what does require linking.
(Edit:) Asio depends on Boost.System and may need Boost.Regex and OpenSSL depending on what you are doing.
To test the current configuration, put this (from here) in the main cpp.

--- Code: ---#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) << " " );
}

--- End code ---
If it compiles you are in business.  Accessing assio can be done by inserting the following line.

--- Code: ---#include <boost/asio.hpp>

--- End code ---
If in working you ever come up with an undefined reference error, it will usually indicate a library does need to be linked.  In this case, return to the main project's search directories settings, but this time on the Linker tab.  Add $(#boost)\lib (or $(#boost.lib) if you set up the lib variable); this should point to the directory with all the lib*.a files.
After this, go to the Linker settings tab and add (using the Add button of course) the needed library or libraries.  (For example, boost_filesystem for the Boost.Filesystem library - basically the name of the file minus the lib and the .a.)

aaronds:
Hi, thanks very much for your response!

However, I still haven't been able to get boost working.


--- Quote from: Alpha on August 24, 2011, 07:00:35 pm ---If in working you ever come up with an undefined reference error, it will usually indicate a library does need to be linked.  In this case, return to the main project's search directories settings, but this time on the Linker tab.  Add $(#boost)\lib (or $(#boost.lib) if you set up the lib variable);

--- End quote ---

My boost installation doesn't have a lib folder (maybe I'm getting the wrong idea)? I've done everything you said and I'm currently getting the undefined reference errors you talked about. In order to check whether this was due to a linker error, I linked all the available libraries (from the stage folder) but the errors persist (they're coming from error_code.hpp). Really not sure why I haven't been able to resolve this :S

Thanks again

Alpha:
Did the minimal code sample I provided compile?
Also, go to Settings->Compiler and debugger...->Build options (tab) and check Save build log and Always output the full command line.  If you post the log here (it should be generated in the project's directory each time you compile), I might be able to see what is going wrong.


--- Quote from: aaronds on August 24, 2011, 04:00:35 pm ---I have built and installed the Boost library, I just need to configure it with my project.

--- End quote ---

--- Quote from: aaronds on August 24, 2011, 10:07:37 pm ---My boost installation doesn't have a lib folder

--- End quote ---
I assume from this the build succeded, so there should be multiple lib*.a files somewhere on your harddrive - the default folder is lib, however, it seems they have gone somewhere else on your computer.  Locate this folder and add it to the linker search directories.

aaronds:

--- Quote from: Alpha on August 25, 2011, 12:20:10 am ---Did the minimal code sample I provided compile?

--- End quote ---
The code example appears to compile, but it doesn't output anything to the CMD window (it just seems to hang...?).


--- Quote from: Alpha on August 25, 2011, 12:20:10 am ---I assume from this the build succeded, so there should be multiple lib*.a files somewhere on your harddrive - the default folder is lib, however, it seems they have gone somewhere else on your computer.  Locate this folder and add it to the linker search directories.

--- End quote ---
I have a range of .lib files but not .a. When I built boost I didn't receive any errors and as far as I know the build was successful. However, I don't have a /lib/ folder, only /libs/ and /stage/lib/. I believe the output of the build was to /boost/bin.v2/libs (all directories created during the build). I didn't see anything else created. Maybe this is where the problem is...?

Navigation

[0] Message Index

[#] Next page

Go to full version