Hi,
I am a newbie. I would like to run a simple threaded program using boost. I
got a sample file see below and compile with the following command
g++ simple.cpp -lthread
I got error
////
In file included from /usr/include/boost/thread/detail/config.hpp:18,
from /usr/include/boost/thread/thread.hpp:15,
from /usr/include/boost/thread.hpp:15,
from simple.cpp:9:
/usr/include/boost/config/requires_threads.hpp:47:5: #error "Compiler
threading support is not turned on. Please set the correct command line
options for threading: -pthread (Linux), -pthreads (Solaris) or -mthreads
(Mingw32)"
In file included from /usr/include/boost/thread/thread.hpp:19,
from /usr/include/boost/thread.hpp:15,
from simple.cpp:9:
/usr/include/boost/thread/mutex.hpp:58: error: `cv_state' was not declared
in
this scope
/usr/include/boost/thread/mutex.hpp:58: error: `state' was not declared in
this
scope
/usr/include/boost/thread/mutex.hpp:58: error: invalid data member
initialization
/usr/include/boost/thread/mutex.hpp:58: error: (use `=' to initialize static
data members)
/usr/include/boost/thread/mutex.hpp:58: error: variable or field `do_lock'
declared void
/usr/include/boost/thread/mutex.hpp:58: error: declaration of `int
boost::mutex::do_lock'
/usr/include/boost/thread/mutex.hpp:56: error: conflicts with previous
declaration `void boost::mutex::do_lock()'
/usr/include/boost/thread/mutex.hpp:59: error: `cv_state' was not declared
in
this scope
/usr/include/boost/thread/mutex.hpp:59: error: `state' was not declared in
this
scope
/usr/include/boost/thread/mutex.hpp:59: error: invalid data member
initialization
/usr/include/boost/thread/mutex.hpp:59: error: variable or field `do_unlock'
declared void
/usr/include/boost/thread/mutex.hpp:59: error: declaration of `int
boost::mutex::do_unlock'
/usr/include/boost/thread/mutex.hpp:57: error: conflicts with previous
declaration `void boost::mutex::do_unlock()'
/usr/include/boost/thread/mutex.hpp:100: error: `cv_state' was not declared
in
this scope
/usr/include/boost/thread/mutex.hpp:100: error: `state' was not declared in
this scope
/usr/include/boost/thread/mutex.hpp:100: error: invalid data member
initialization
/usr/include/boost/thread/mutex.hpp:100: error: variable or field `do_lock'
declared void
/usr/include/boost/thread/mutex.hpp:100: error: declaration of `int
boost::try_mutex::do_lock'
/usr/include/boost/thread/mutex.hpp:97: error: conflicts with previous
declaration `void boost::try_mutex::do_lock()'
/usr/include/boost/thread/mutex.hpp:101: error: `cv_state' was not declared
in
this scope
/usr/include/boost/thread/mutex.hpp:101: error: `state' was not declared in
this scope
/usr/include/boost/thread/mutex.hpp:101: error: invalid data member
initialization
/usr/include/boost/thread/mutex.hpp:101: error: variable or field
`do_unlock'
declared void
/usr/include/boost/thread/mutex.hpp:101: error: declaration of `int
boost::try_mutex::do_unlock'
/usr/include/boost/thread/mutex.hpp:99: error: conflicts with previous
declaration `void boost::try_mutex::do_unlock()'
/usr/include/boost/thread/mutex.hpp:144: error: `cv_state' was not declared
in
this scope
/usr/include/boost/thread/mutex.hpp:144: error: `state' was not declared in
this scope
/usr/include/boost/thread/mutex.hpp:144: error: invalid data member
initialization
/usr/include/boost/thread/mutex.hpp:144: error: variable or field `do_lock'
declared void
/usr/include/boost/thread/mutex.hpp:144: error: declaration of `int
boost::timed_mutex::do_lock'
/usr/include/boost/thread/mutex.hpp:140: error: conflicts with previous
declaration `void boost::timed_mutex::do_lock()'
/usr/include/boost/thread/mutex.hpp:145: error: `cv_state' was not declared
in
this scope
/usr/include/boost/thread/mutex.hpp:145: error: `state' was not declared in
this scope
/usr/include/boost/thread/mutex.hpp:145: error: invalid data member
initialization
/usr/include/boost/thread/mutex.hpp:145: error: variable or field
`do_unlock'
declared void
/usr/include/boost/thread/mutex.hpp:145: error: declaration of `int
boost::timed_mutex::do_unlock'
/usr/include/boost/thread/mutex.hpp:143: error: conflicts with previous
declaration `void boost::timed_mutex::do_unlock()'
In file included from /usr/include/boost/thread.hpp:19,
from simple.cpp:9:
/usr/include/boost/thread/once.hpp:35: error: type specifier omitted for
parameter `once_flag'
/usr/include/boost/thread/once.hpp:35: error: parse error before `&' token
In file included from /usr/include/boost/thread.hpp:20,
from simple.cpp:9:
/usr/include/boost/thread/recursive_mutex.hpp:55: error: `cv_state' was not
declared in this scope
/usr/include/boost/thread/recursive_mutex.hpp:55: error: `state' was not
declared in this scope
/usr/include/boost/thread/recursive_mutex.hpp:55: error: invalid data member
initialization
/usr/include/boost/thread/recursive_mutex.hpp:55: error: variable or field `
do_lock' declared void
/usr/include/boost/thread/recursive_mutex.hpp:55: error: declaration of `int
boost::recursive_mutex::do_lock'
/usr/include/boost/thread/recursive_mutex.hpp:53: error: conflicts with
previous declaration `void boost::recursive_mutex::do_lock()'
/usr/include/boost/thread/recursive_mutex.hpp:56: error: `cv_state' was not
declared in this scope
/usr/include/boost/thread/recursive_mutex.hpp:56: error: `state' was not
declared in this scope
/usr/include/boost/thread/recursive_mutex.hpp:56: error: invalid data member
initialization
/usr/include/boost/thread/recursive_mutex.hpp:56: error: variable or field `
do_unlock' declared void
/usr/include/boost/thread/recursive_mutex.hpp:56: error: declaration of `int
boost::recursive_mutex::do_unlock'
/usr/include/boost/thread/recursive_mutex.hpp:54: error: conflicts with
previous declaration `void boost::recursive_mutex::do_unlock()'
/usr/include/boost/thread/recursive_mutex.hpp:103: error: `cv_state' was not
declared in this scope
/usr/include/boost/thread/recursive_mutex.hpp:103: error: `state' was not
declared in this scope
/usr/include/boost/thread/recursive_mutex.hpp:103: error: invalid data
member
initialization
/usr/include/boost/thread/recursive_mutex.hpp:103: error: variable or field
`
do_lock' declared void
/usr/include/boost/thread/recursive_mutex.hpp:103: error: declaration of
`int
boost::recursive_try_mutex::do_lock'
/usr/include/boost/thread/recursive_mutex.hpp:100: error: conflicts with
previous declaration `void boost::recursive_try_mutex::do_lock()'
/usr/include/boost/thread/recursive_mutex.hpp:104: error: `cv_state' was not
declared in this scope
/usr/include/boost/thread/recursive_mutex.hpp:104: error: `state' was not
declared in this scope
/usr/include/boost/thread/recursive_mutex.hpp:104: error: invalid data
member
initialization
/usr/include/boost/thread/recursive_mutex.hpp:104: error: variable or field
`
do_unlock' declared void
/usr/include/boost/thread/recursive_mutex.hpp:104: error: declaration of
`int
boost::recursive_try_mutex::do_unlock'
/usr/include/boost/thread/recursive_mutex.hpp:102: error: conflicts with
previous declaration `void boost::recursive_try_mutex::do_unlock()'
/usr/include/boost/thread/recursive_mutex.hpp:154: error: `cv_state' was not
declared in this scope
/usr/include/boost/thread/recursive_mutex.hpp:154: error: `state' was not
declared in this scope
/usr/include/boost/thread/recursive_mutex.hpp:154: error: invalid data
member
initialization
/usr/include/boost/thread/recursive_mutex.hpp:154: error: variable or field
`
do_lock' declared void
/usr/include/boost/thread/recursive_mutex.hpp:154: error: declaration of
`int
boost::recursive_timed_mutex::do_lock'
/usr/include/boost/thread/recursive_mutex.hpp:150: error: conflicts with
previous declaration `void boost::recursive_timed_mutex::do_lock()'
/usr/include/boost/thread/recursive_mutex.hpp:155: error: `cv_state' was not
declared in this scope
/usr/include/boost/thread/recursive_mutex.hpp:155: error: `state' was not
declared in this scope
/usr/include/boost/thread/recursive_mutex.hpp:155: error: invalid data
member
initialization
/usr/include/boost/thread/recursive_mutex.hpp:155: error: variable or field
`
do_unlock' declared void
/usr/include/boost/thread/recursive_mutex.hpp:155: error: declaration of
`int
boost::recursive_timed_mutex::do_unlock'
/usr/include/boost/thread/recursive_mutex.hpp:153: error: conflicts with
previous declaration `void boost::recursive_timed_mutex::do_unlock()'
/////////////////////////
If I use commend g++ simple.cpp -pthread
I got error
////////
/tmp/cchxK5CW.o(.text+0x66): In function `main':
: undefined reference to
`boost::thread::thread[in-charge](boost::function0