Reputation: 521
When attempting to compile some sample C++ code using the Boost Threading library I get this compile error:
Insanity@MintBook ~/Desktop> clang++ btest.cpp -o btest
In file included from btest.cpp:2:
In file included from /usr/local/include/boost/thread.hpp:17:
In file included from /usr/local/include/boost/thread/once.hpp:20:
In file included from /usr/local/include/boost/thread/pthread/once_atomic.hpp:20:
In file included from /usr/local/include/boost/atomic.hpp:12:
In file included from /usr/local/include/boost/atomic/atomic.hpp:17:
In file included from /usr/local/include/boost/atomic/detail/platform.hpp:22:
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:961:64: error: no matching
constructor for initialization of 'storage_type' (aka
'boost::atomics::detail::storage128_type')
explicit base_atomic(value_type const& v) BOOST_NOEXCEPT : v_(0)
^ ~
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:932:28: note: candidate
constructor (the implicit copy constructor) not viable: no known
conversion from 'int' to 'const boost::atomics::detail::storage128_type'
for 1st argument
struct BOOST_ALIGNMENT(16) storage128_type
^
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:932:28: note: candidate
constructor (the implicit default constructor) not viable: requires 0
arguments, but 1 was provided
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:968:22: error: no viable
conversion from 'int' to 'storage_type' (aka
'boost::atomics::detail::storage128_type')
storage_type tmp = 0;
^ ~
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:932:28: note: candidate
constructor (the implicit copy constructor) not viable: no known
conversion from 'int' to 'const boost::atomics::detail::storage128_type &'
for 1st argument
struct BOOST_ALIGNMENT(16) storage128_type
^
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:983:22: error: no viable
conversion from 'int' to 'storage_type' (aka
'boost::atomics::detail::storage128_type')
storage_type tmp = 0;
^ ~
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:932:28: note: candidate
constructor (the implicit copy constructor) not viable: no known
conversion from 'int' to 'const boost::atomics::detail::storage128_type &'
for 1st argument
struct BOOST_ALIGNMENT(16) storage128_type
^
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:997:22: error: no viable
conversion from 'int' to 'storage_type' (aka
'boost::atomics::detail::storage128_type')
storage_type expected_s = 0, desired_s = 0;
^ ~
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:932:28: note: candidate
constructor (the implicit copy constructor) not viable: no known
conversion from 'int' to 'const boost::atomics::detail::storage128_type &'
for 1st argument
struct BOOST_ALIGNMENT(16) storage128_type
^
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:997:38: error: no viable
conversion from 'int' to 'storage_type' (aka
'boost::atomics::detail::storage128_type')
storage_type expected_s = 0, desired_s = 0;
^ ~
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:932:28: note: candidate
constructor (the implicit copy constructor) not viable: no known
conversion from 'int' to 'const boost::atomics::detail::storage128_type &'
for 1st argument
struct BOOST_ALIGNMENT(16) storage128_type
^
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:1013:22: error: no viable
conversion from 'int' to 'storage_type' (aka
'boost::atomics::detail::storage128_type')
storage_type expected_s = 0, desired_s = 0;
^ ~
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:932:28: note: candidate
constructor (the implicit copy constructor) not viable: no known
conversion from 'int' to 'const boost::atomics::detail::storage128_type &'
for 1st argument
struct BOOST_ALIGNMENT(16) storage128_type
^
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:1013:38: error: no viable
conversion from 'int' to 'storage_type' (aka
'boost::atomics::detail::storage128_type')
storage_type expected_s = 0, desired_s = 0;
^ ~
/usr/local/include/boost/atomic/detail/gcc-atomic.hpp:932:28: note: candidate
constructor (the implicit copy constructor) not viable: no known
conversion from 'int' to 'const boost::atomics::detail::storage128_type &'
for 1st argument
struct BOOST_ALIGNMENT(16) storage128_type
^
7 errors generated.
The code I am trying to compile is some sample code for Boost threading, however I have determined that theses errors are not exclusive to this particular piece of source code:
#include <iostream>
#include <boost/thread.hpp>
using namespace std;
class MyRunnable {
public:
MyRunnable(int id, boost::mutex* mutex, boost::barrier* bar) {
this->id = id;
this->mutex = mutex;
this->bar = bar;
}
// The entry point for a thread
void operator()() {
for(int i = 0; i < 10; ++i) {
boost::mutex::scoped_lock lock(*mutex);
cout << "id: " << this->id << ", " << i << endl;
}
// all done, wait at the barrier.
// wait() returns when everyone has met at the barrier
bar->wait();
}
private:
int id;
boost::mutex* mutex;
boost::barrier* bar;
};
int main() {
boost::mutex io_mutex;
// this barrier will wait for two invocations of wait()
boost::barrier my_barrier(2);
cout << "Starting two counting threads..." << endl;
// the boost::mutex cannot be copied (for obvious reasons)
// so we must pass the pointer to the mutex.
boost::thread thread1(MyRunnable(1, &io_mutex, &my_barrier));
boost::thread thread2(MyRunnable(2, &io_mutex, &my_barrier));
thread1.join(); // wait for thread1 to finish
// Note how the program doesn't return until all threads are dead
return 0;
}
I am new to the world of C++ programming and I have no idea what is going wrong. Any help would be much appreciated.
Upvotes: 1
Views: 3505