我從the website的壓縮文件中提取了源代碼,並將它們放在Code :: Blocks''include'文件夾中,但即使如此,它也無法編譯提供的'hello.cpp'示例。我是否需要構建TinyThread ++?
(僅供參考:)
#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++。我錯過了什麼;像,我需要建立圖書館或任何東西?如果是這樣,怎麼樣?
你很可能需要鏈接到庫。這是一個非常好的錯誤提示:http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-doi-i-fix – chris
@chris雖然這引發了我*很多最近的錯誤,我怎麼能鏈接庫?你或其他人可以向我解釋嗎? :O – Mutoh
這裏不適用,但是如果你使用IDE,你通常可以進入鏈接器項目設置並添加庫。 MSVC允許你執行'#pragma comment(lib,「nameoflibrary.lib」)',並且通過命令行使用'-llibraryname'。 – chris