Use the boost library to Write multi-threaded programs:
# Define boost_data_time_source
# Define boost_thread_no_lib
# Include <boost/thread. HPP>
# Include <iostream>
Using namespace STD;
Using namespace boost;
Void Hello ()
{
STD: cout <
"Hello world, I'm a thread! "
<STD: Endl;
}
Int main (INT argc, char * argv [])
{
Boost: thread thrd (& Hello );
// Wait until the thread ends
Thrd. Join ();
Return 0;
}
The console prompts an error during compilation:
* *** Internal builder is used for build ****
G ++-O0-G3-wall-C-fmessage-length = 0-osrc/test. O ../src/test. cpp
G ++ -otest.exe src/test. o
Src/test. O: In function 'main ':
C:/Eclipse/workspace/test/debug/../src/test. cpp: 22: Undefined reference to 'boost: thread: Join ()'
C:/Eclipse/workspace/test/debug/../src/test. cpp: 20: Undefined reference to 'boost: thread ::~ Thread ()'
C:/Eclipse/workspace/test/debug/../src/test. cpp: 20: Undefined reference to 'boost: thread ::~ Thread ()'
Src/test. O: In function 'thread <void (*) ()> ':
D:/Eclipse/mingw/bin /.. /lib/GCC/i686-pc-mingw32/4.5.2 /.. /.. /.. /.. /include/Boost/thread/detail/thread. HPP: 204: Undefined reference to 'boost: thread: start_thread ()'
Collect2: LD returned 1 exit status
Build error occurred, build is stopped
Time consumed: 6062 Ms.
At the same time, two lines in the source code are prompted with an error.
Solution:
Right-click the project and choose Properties.
Open the following settings page:
Open C/C ++ build on the left, find mingw C ++ linker --> libraries in the list under tool settings, and click the plus sign in the upper right corner of libraries, add "boost_thread ",
Click "OK", click "Apply", and then click "OK" to exit. Re-compile, no problem.