nww04
nww04

Reputation: 1857

How to build and configure boost.thread in CodeBlocks on Windows

I just wanna ask this very trivial question, I do not know if this the right question or if this one has been asked before and I know this can be solved by just visiting the documentation on boost. But I am really lost and stuck configuring boost.thread in C::B.

I am just a beginner when it comes to this and currently learning how to make windows app, well not seriously, just for learning purposes. I just notice that I really need the concept of multi-threading just to make it work. So I decided to use the Boost library, I did exactly what boost wiki says on building the libraries and I think I did not do something wrong.

I ran some couple of codes from the documentation that are header-only and it works flawlessly, but there are libraries included on boosts which requires special treatment of some sort including boost.thread which I am having difficulties. I know #includ-ing it on my file will not make Boost.thread works. I got errors from this basic code I found from an online tutorial (the very first code on multithreading page I found there) produces an error which says no such file directory.

||=== Multithreading_sample, Debug ===|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev          
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|1|boost/thread.hpp: No such 
file or directory|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev    
C++\App\Multithreading_sample\Multithreading_sample\main.cpp||In function `void   
wait(int)':|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev  
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|6|error: `boost' has not   
been declared|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev 
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|6|error: `boost' has not 
been declared|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev    
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|6|error: `seconds' cannot 
be used as a function|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev   
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|6|error: `sleep' undeclared 
(first use this function)|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev 
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|6|error: (Each undeclared 
identifier is reported only once for each function it appears in.)|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev   
C++\App\Multithreading_sample\Multithreading_sample\main.cpp||In function `int main()':|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev  
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|20|error: `boost' has not 
been declared|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev   
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|20|error: expected `;' 
before "t"|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev   
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|20|warning: statement is a   
reference, not call, to function `thread'|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev   
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|20|warning: statement has 
no effect|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev   
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|21|error: `t' undeclared 
(first use this function)|
||=== Build finished: 9 errors, 2 warnings ===|

and for which I know it doesn't detect my boost.thread library, I don't know where to go in this part. I've searched google but I think my best bet is to build the 1boost.thread1 separately as shown here, and I do not know what to do next.

Upvotes: 1

Views: 1604

Answers (1)

nww04
nww04

Reputation: 1857

Finally, after days of research and googling and cross referencing multitude of solution over the web I finally made the first code on the site I provided.

first what I did is that I included the extract_directory as the base under builtin fields in global variables. Then I went to project options and I clicked on the name of the project in hierarchy and search directories I added the $(#boost.include) on compiler tab and $(boost)\stage\lib on linker tab.

I started again from scratch in rebuilding boost(esp building boost.thread library) and I follow again what is exactly written on the documentation and then I finally got some error saying undefined reference error on Boost::system. What I did to solve this problem is to link my project against that boost.system (which is in my case was the file in my stage\lib folder).

I link this library on my project libboost_system-mgw34-mt-1_51.a

When I compile my program, an error occurred saying undefined reference to boost::chrono, which library name is:

libboost_chrono-mgw34-mt-1_51.a

and I also link my project against it, the same way I did for boost::system.

And it compiles! With no warnings whatsoever, what I learned from this experience is that I have to look for the libraries needed, what I am doing so far is to just link the boost.thread library and error just keep on saying undefined reference error to boost.system which I am not aware has something to do with boost threads or with other libraries(this is the first error I encountered before I messed things up). I think there are multiple function calls inside each boost libraries that are on another libraries so I have to link with them also that requires such call.

Thank you guys for your kind responses.

Upvotes: 1

Related Questions