Boost/Thread.hpp编译错误
Compilation error with Boost/Thread.hpp
当尝试使用Boost Threading库编译一些示例c++代码时,我得到这个编译错误:
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.
我试图编译的代码是Boost线程的一些示例代码,但是我已经确定这些错误并不专属于这段特定的源代码:
#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;
}
我是c++编程世界的新手,我不知道哪里出了问题。
这是一个已知的问题,在Boost主干中修复。
相关文章:
- std::is_base_of表示ctor编译错误
- Qt5:使用QCommandLineParser类时出现奇怪的编译错误
- 如何修复sfml c++代码编译错误
- 使用 MATLAB 编码器生成C++代码:编译错误"undefined reference to `rgb2gray_tbb_real64'"
- 使用外部SDK工具链文件在VisualStudio上生成项目编译错误
- vscode下的Arduino代码出现意外编译错误
- 第三方 API 中的编译错误 - Visual Studio
- std::cout输出int时出现编译错误
- 奇怪的代码抛出编译错误模板< J,int aSize=10> C2143:语法错误:在"<"之前缺少";"
- 提升图广度优先搜索前置编译错误
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 使用带有 ref 参数的成员函数创建线程时出现编译错误
- 我在C++中遇到了这个奇怪的编译错误
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- 使用 std::enable_if 限制派生类的模板参数时出现编译错误
- 现代OpenGL和GLEW Libraray的编译错误
- C++ 编译错误:意外的类型名称"字符串":预期的表达式
- C ++程序编译错误,找不到/访问文件
- 使用直接大括号初始化时,C++ 编译错误"声明末尾的预期";"
- 为什么传递非静态成员函数会导致编译错误?