我已经从位于 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/