c++ - 我需要构建 TinyThread++ 吗?

标签 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++ 上。我错过了什么吗?比如,我需要构建库还是什么?如果是,怎么办?

最佳答案

来自存档中的 readme.txt:

Using TinyThread++

To use TinyThread++ in your own project, just add tinythread.cpp and tinythread.h to your project. In your own code, do:

#include <tinythread.h>
using namespace tthread;

If you wish to use the fast_mutex class, inlude fast_mutex.h:

#include <fast_mutex.h>

仅包含 header 会导致无法解析的符号,因为 .cpp 不会被编译。

关于c++ - 我需要构建 TinyThread++ 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13318419/

相关文章:

java - 引用类型的 volatile - 它是否总是避免由于 JMM 而发布引用问题?

c - 获取线程函数c的参数

Java 文件 I/O 吞吐量下降

java - 不使用 Thread.Join() ,我怎样才能实现相同的功能

java - 线程转储显示不正确的线程状态

c++ - 帮助解决 c 错误

c++ - ConsoleApplication4.exe 已停止工作。 Windows 将关闭程序并通知是否有可用的解决方案

c++ - 尝试 libssh 身份验证时的核心转储

c++ - 在 C++ 中使用结构作为数据类型初始化 vector 的 vector

c++ - 无符号字符串构造不可能