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 (http://wiki.codeblocks.org/index.php?title=Creating_a_new_project#The_project_wizard) 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 (http://www.boost.org/doc/libs/1_47_0/more/getting_started/windows.html#header-only-libraries) of what does require linking.
(Edit:) Asio depends (http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/using.html) on Boost.System and may need Boost.Regex and OpenSSL (http://www.openssl.org/) depending on what you are doing.
To test the current configuration, put this (from here (http://www.boost.org/doc/libs/1_47_0/more/getting_started/windows.html#build-a-simple-program-using-boost)) in the main cpp.
#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) << " " );
}
If it compiles you are in business. Accessing assio can be done by inserting the following line.
#include <boost/asio.hpp>
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 (http://www.boost.org/doc/libs/1_47_0/libs/filesystem/index.html) library - basically the name of the file minus the lib and the .a.)
Hi, I've just rebuilt boost and it looks a bit more promising. I hadn't configured the build to compile with MinGW previously (it had still built though). I'll edit once I try to build a project.
The code example appears to compile, but it doesn't output anything to the CMD window (it just seems to hang...?).
Oh, I should have mentioned all it does is multiply the input number by 3 (you need to type a number and press enter).
My bad, I only scan-read the code quickly before running it.
Edit:
Seem much closer than before. One last error to get rid of when attempting to use asio.
undefined reference to `WSACleanup@8
undefined reference to `WSACleanup@0
Both errors originate from winsock_init.ipp. I've tried linking a few libraries (this time I have the .a files, one of the libs I tried linking was system) but I haven't resolved the issue.
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 (http://www.boost.org/doc/libs/1_47_0/libs/filesystem/index.html) library - basically the name of the file minus the lib and the .a.)
I don't have any .a file that has asio in the name.
If it still does not work, post a build log.
go to Settings->Compiler and debugger...->Build options (tab) and check Save build log and Always output the full command line.
I don't seem to have a build options tab :S
Thanks again for your help.
I have problems with Code::Blocks configuration for Boost.
Description of problem:
1. During compilation of code supplied by Alpha, following error messages are appear (have no compilation problems if not using Boost)
a) C:\Program Files\CodeBlocks\Boost\include\boost-1_47\boost\lambda\detail\lambda_functor_base.hpp|227| [ skipping 6 instantiation contexts ]|
b) C:\Program Files\CodeBlocks\Boost\include\boost-1_47\boost\lambda\detail\operator_lambda_func_base.hpp:60|56|instantiated from 'boost::lambda::detail::binary_rt<boost::lambda::bitwise_action<boost::lambda::leftshift_action>, boost::tuples::tuple<std::basic_ostream<char>&, boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::multiply_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, const int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::nu|
c) C:\Program Files\CodeBlocks\Boost\include\boost-1_47\boost\lambda\detail\lambda_functors.hpp:202|50|instantiated from 'typename inherited::sig<boost::tuples::tuple<const A&> >::type boost::lambda::lambda_functor<Base>::operator()(const A&) const [with A = int, T = boost::lambda::lambda_functor_base<boost::lambda::bitwise_action<boost::lambda::leftshift_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::bitwise_action<boost::lambda::leftshift_action>, boost::tuples::tuple<std::basic_ostream<char>&, boost::lambda::lambda_functor<boost::lambda::lamb|
d) c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.5.2\include\c++\bits\stl_algo.h:4185|2|instantiated from '_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = std::istream_iterator<int>, _Funct = boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::bitwise_action<boost::lambda::leftshift_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::bitwise_action<boost::lambda::leftshift_action>, boost::tuples::tuple<std::basic_ostream<char>&, boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boo|
2) Used software versions
a. Code::Blocks 10.05
b. MinGW 4.6
c. Boost 1.47.0
3) Boost libraries were built after several manipulations described below
a. In file \boost_1_47_0\bootstrap.bat line set toolset=msvc was replaced with line set toolset=gcc
b. In file \boost_1_47_0\tools\build\v2\engine\build.bat under the procedure :Guess_toolset updates the MinGW entry to point to the correct folder:
call :Clear_Error
if EXIST "C:\Program Files\CodeBlocks\MinGW\bin\gcc.exe" (
set "BOOST_JAM_TOOLSET=mingw"
set "BOOST_JAM_TOOLSET_ROOT=C:\Program Files\CodeBlocks\MinGW\"
goto :eof)
c. In file \boost_1_47_0\tools\build\v2\engine\build.bat, removed all other blocks of code similar to the above codeblock from the procedure :Guess_toolset
d. Compiled and Built the Boost C++ Library binaries
i. In CMD (command line) enter the command: c:\boost_1_47_0\bootstrap.bat, it successfully built the executable Bjam.exe
ii. To build the Boost Library binaries entered command in CMD:
bjam --toolset=gcc --build-type=complete "--prefix=C:\Program Files\CodeBlocks\Boost" install
following Boost directories hierarchy was created:
c:\Program Files\CodeBlocks\boost\
lib (contain built libraries, only files with extension *.a)
include\boost-1_47\boost\... (header files and e.t.c)
4. Setting Code::Blocks Global Variables
a. In Global Variable Editor defined new Variables
i. In Current Set clicked on New button and entered variable name boost
ii. In Current Variable clicked on New button and entered variable name boost
iii. In filed base entered following path: C:\Program Files\CodeBlocks\Boost\include\boost-1_47
iv. In field lib entered following path: C:\Program Files\CodeBlocks\Boost\lib
5. Setting Code::Blocks Project Build Options
a. In Project->Build options...
i. Ensured that the overall name of the project is selected in the left-hand column
ii. In Search directories tab Compiler sub-tab filed entered $(#boost)
iii. In Search directories tab Linker sub-tab filed entered $(#boost.lib)
Alpha thanks for advise,
I have installed Qt SDK (4.7), it comes with MinGW 4.5, built inside package.
I will uninstall it and try to compile above mentioned code one more time
#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) << " " );
}
In any case thanks for advise.
I will response if succeeded or not.
hello all , i have the same problem getting boost to work with CB .
i can compile this source 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) << " " );
}
i used these command to compile boost :
boost is extracted to F:\
and main folder address is :
here are the commands :
F:\
F:\ cd Boost_1_44_0
F:\ Boost_1_44_0> bootstrap.bat
F:\ Boost_1_44_0>bjam toolset=gcc --build-type=complete stage
-------------------
the above didnt do any good so i wrote this and actually compiled just fine :
F:\ Boost_1_44_0>bjam variant=debug,release link=static address-model=32
and then
F:\boost_1_49_0>bjam toolset=gcc variant=debug,release link=static threading=multi address-model=32 --build-type=complete stage
then when i tried to compile a thread example :
#include <boost/thread.hpp>
#include <iostream>
void wait(int seconds)
{
boost::this_thread::sleep(boost::posix_time::seconds(seconds));
}
boost::mutex mutex;
void thread()
{
for (int i = 0; i < 5; ++i)
{
wait(1);
mutex.lock();
std::cout << "Thread " << boost::this_thread::get_id() << ": " << i << std::endl;
mutex.unlock();
}
}
int main()
{
boost::thread t1(thread);
boost::thread t2(thread);
t1.join();
t2.join();
}
which failed miserably with these errors :
obj\Debug\main.o||In function `Z6threadv':|
D:\Documents and Settings\Master\My Documents\Projects\Boost Example\main.cpp|18|undefined reference to `_imp___ZN5boost11this_thread6get_idEv'|
obj\Debug\main.o||In function `main':|
D:\Documents and Settings\Master\My Documents\Projects\Boost Example\main.cpp|27|undefined reference to `_imp___ZN5boost6thread4joinEv'|
D:\Documents and Settings\Master\My Documents\Projects\Boost Example\main.cpp|28|undefined reference to `_imp___ZN5boost6thread4joinEv'|
D:\Documents and Settings\Master\My Documents\Projects\Boost Example\main.cpp|28|undefined reference to `_imp___ZN5boost6threadD1Ev'|
D:\Documents and Settings\Master\My Documents\Projects\Boost Example\main.cpp|28|undefined reference to `_imp___ZN5boost6threadD1Ev'|
D:\Documents and Settings\Master\My Documents\Projects\Boost Example\main.cpp|28|undefined reference to `_imp___ZN5boost6threadD1Ev'|
D:\Documents and Settings\Master\My Documents\Projects\Boost Example\main.cpp|28|undefined reference to `_imp___ZN5boost6threadD1Ev'|
F:\boost_1_49_0\boost\thread\win32\thread_data.hpp|161|undefined reference to `_imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE'|
obj\Debug\main.o||In function `thread<void (*)()>':|
F:\boost_1_49_0\boost\thread\detail\thread.hpp|205|undefined reference to `_imp___ZN5boost6thread12start_threadEv'|
||=== Build finished: 9 errors, 0 warnings (0 minutes, 49 seconds) ===|
i configured CB like this :
right clicked on the active project >build options >Debug>Search Directories >Compiler:
added these:
$(#boost.include)
F:\boost_1_49_0
F:\boost_1_49_0\boost
F:\boost_1_49_0\stage\lib
and under linker i added:
$(#boost.lib)
F:\boost_1_49_0\stage\lib
F:\boost_1_49_0\libs
then i added to the Linker section and selected all of the files in stage/libs : these are :
here is the pic :
(http://upload.ustmb.ir/uploads/13335642651.jpg)
and for the variable part :
i have this :
(http://upload.ustmb.ir/uploads/13335644061.jpg)
--------------------------
what is it that i am missing ?
Master: Keep in mind that boost has they support, here we support C::B and your question is quite off topic!
yes you are right , but since it was concerned with CB in terms of configuration and again because of using a svn version , i thought there might be sth wrong with the CB svn or sth has changed that i am unware of .so basically the best place to find about this would be here to my opinion .
and googling got me here by the way , thought i could use some help with the people working daily with CB .
You miss to inspect / provide the full build log (see my sig).
here is the full build log .
http://upload.ustmb.ir/uploads/13335802852.zip
Thank you in advance
Also don't use full paths to the libraries, just their names. In the Build options -> Linker setting -> Link libraries
If I remember correctly using full paths is known to fail.
thank you dear oBFusCATed , i tested your suggestion , but it turned up that it was wrong . actually there is nothing wrong with the full path .
here is the answer though :
http://stackoverflow.com/questions/10022706/having-issue-in-configuring-boost-with-codeblocks/10035917#10035917
i rebuilt the boost with
bjam toolset=gcc --build-type=complete stage variant=debug,release threading=multi link=static
and then added the following line to my source code
#define BOOST_THREAD_USE_LIB
and there it goes :) compiling , linking just fine :)
and i didnt change any of my previouse configurations , just rebuilt and added that line , done :)
thanks again everyone