Solve undefined reference to 'boost: thread: start_thread () 'in eclipse3.6.1 ()'

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.