我需要构建TinyThread ++吗?

时间:2012-11-10 01:42:59

标签: c++ multithreading

我从the website的zip文件中提取了源代码并将它们放在Code :: Blocks的'include'文件夹中,但即使这样,它也无法编译提供的'hello.cpp'示例。

(供参考:)

#include <iostream>
#include <tinythread.h>

using namespace std;
using namespace tthread;


// This is the child thread function
void HelloThread(void * aArg)
{
  cout << "Hello world!" << endl;
}

// This is the main program (i.e. the main thread)
int main()
{
  // Start the child thread
  thread t(HelloThread, 0);

  // Wait for the thread to finish
  t.join();
}

这些是以下错误:

|41|undefined reference to `tthread::thread::thread(void (*)(void*), void*)'|
|44|undefined reference to `tthread::thread::join()'|
|44|undefined reference to `tthread::thread::~thread()'|
|44|undefined reference to `tthread::thread::~thread()'|

wxDev-C ++也是如此。我错过了什么;比如,我需要构建库或任何东西吗?如果是这样,怎么样?

2 个答案:

答案 0 :(得分:3)

从档案内的readme.txt:

  

使用TinyThread ++

     

要在您自己的项目中使用TinyThread ++,只需添加tinythread.cpp和   tinythread.h到你的项目。在您自己的代码中,执行:

#include <tinythread.h>
using namespace tthread;
  

如果你想使用fast_mutex类,请加入fast_mutex.h:

#include <fast_mutex.h>

只包含标题会导致未解析的符号,因为.cpp不会被编译。

答案 1 :(得分:0)

TinyThread很小。

除了包含标题之外,您只需将TinyThread.cpp添加到项目中,或确保它作为项目的一部分构建。

在我将CPP文件添加到项目中之前,VC ++中发生了特定错误。

线程类和方法没有得到编译。

相关问题