试图在 Linux 中使用我在 Windows 中创建的线程类。为其选择 Netbeans,并在我指定Linker > Additional Library Directories
为/usr/local/boost_1_53_0
Under的项目设置中Libraries
,我指定boost_thread-mt
UnderC++ Compiler > Include Directories
我指定/usr/local/boost_1_53_0
thread.h
并且Thread.cpp
是我的文件。Thread.hpp
属于升压。
显示的错误在我包含的行中#include <boost/thread/thread.hpp>
,错误是:
/usr/local/boost_1_53_0/boost/bind/bind.hpp: In member function ‘void
boost::_bi::list1<A1>::operator()(boost::_bi::type<void>, F&, A&, int)
[with F = unsigned int (**)(void*), A = boost::_bi::list0, A1 =
boost::_bi::value<void*>]’: In file included from
/usr/local/boost_1_53_0/boost/bind.hpp:22:0,
from /usr/local/boost_1_53_0/boost/thread/detail/thread.hpp:29,
from /usr/local/boost_1_53_0/boost/thread/thread.hpp:22,
from ../../../TSDK-master/src/Core/source/thread.h:72,
from ../../../TSDK-master/src/Core/source/Thread.cpp:95:
/usr/local/boost_1_53_0/boost/bind/bind_template.hpp:20:59:
instantiated from ‘boost::_bi::bind_t<R, F, L>::result_type
boost::_bi::bind_t<R, F, L>::operator()() [with R = void, F = unsigned
int (**)(void*), L = boost::_bi::list1<boost::_bi::value<void*> >,
boost::_bi::bind_t<R, F, L>::result_type = void]’
/usr/local/boost_1_53_0/boost/thread/detail/thread.hpp:117:17:
instantiated from ‘void boost::detail::thread_data<F>::run() [with F =
boost::_bi::bind_t<void, unsigned int (**)(void*),
boost::_bi::list1<boost::_bi::value<void*> > >]’
../../../TSDK-master/src/Core/source/Thread.cpp:202:50: instantiated
from here /usr/local/boost_1_53_0/boost/bind/bind.hpp:253:9: error:
‘boost::_bi::unwrapper<F>::unwrap [with F = unsigned int
(**)(void*)]((* & f), 0l)’ cannot be used as a function
我完全不知道是什么原因造成的。有人可以帮忙吗?
编辑:
thread.h 的一部分
#include <boost/thread/thread.hpp>
#include <cstdio>
class Thread
{
protected:
boost::thread* m_Thread;
unsigned int id;
private:
bool m_pause;
boost::mutex m_pause_mutex;
boost::condition_variable m_pause_changed;
bool threadCreated;
public:
Thread();
Thread(unsigned int id);
~Thread();
bool Start();
bool CreateThread(unsigned int Function(void* pParam),void *pParam);
void Terminate();
unsigned int myThreadProc(void* param);
bool IsRunning();
bool IsStarted();
protected:
virtual unsigned int ThreadProc() = 0;
};
和thread.cpp的一部分
#include "thread.h"
Thread::Thread() : m_Thread(NULL), m_pause(true), threadCreated(false), id(NULL)
{
}//Thread ctor
Thread::Thread(unsigned int _id) : m_Thread(NULL), id(_id), threadCreated(false), m_pause(true)
{}
Thread::~Thread()
{
if (NULL != m_Thread) { delete m_Thread; }
}
unsigned int Thread::GetThreadID() { return id; }//GetThreadID
bool Thread::Start()
{
m_Thread = new boost::thread(&Thread::myThreadProc, this, this);
threadCreated = true;
return threadCreated;
}
bool Thread::CreateThread(unsigned int Function(void* pFunctionParam),void *pParam)
{
//Receives Thread Function,pParam as Arguments and starts Thread.
m_Thread= new boost::thread(&Function,pParam);
threadCreated = true;
return threadCreated;
}
void Thread::Terminate()
{
if (NULL != m_Thread) {
m_Thread->join();
m_Thread=0;
}
else {printf("No thread was created\n");}
}
unsigned int Thread::myThreadProc(void* param)
{
Thread* ourBoostThread = (Thread*) param;
int ret = ourBoostThread->ThreadProc();
return ret;
}//_ThreadProc
bool Thread::IsRunning() { return !m_pause; }
bool Thread::IsStarted() { return threadCreated; }
第 202 行是bool Thread::IsStarted() { return threadCreated; }