0

I've extracted the sources from the zip file at the website and put them in Code::Blocks' 'include' folder, but even then it cannot compile the provided 'hello.cpp' example.

(For reference:)

#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();
}

And these are the following errors:

|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()'|

The same thing happens with wxDev-C++. Am I missing something; like, do I need to build the libraries or anything? If so, how?

Mutoh
  • 358
  • 3
  • 18
  • 1
    You most likely need to link to the libraries. This is a pretty good reference on the error: http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – chris Nov 10 '12 at 01:49
  • @chris While this enlighted me *a lot* on many recent errors, how exactly can I link libraries? Could you or someone else explain it to me? :O – Mutoh Nov 10 '12 at 01:59
  • It doesn't apply here, but if you use an IDE, you can generally go into your linker project settings and add the library. MSVC lets you do `#pragma comment(lib, "nameoflibrary.lib")`, and by command line, use `-llibraryname`. – chris Nov 10 '12 at 02:11

2 Answers2

3

From the readme.txt inside the archive:

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>

Just including the header leads to unresolved symbols because the .cpp does not get compiled.

Community
  • 1
  • 1
Anonymous Coward
  • 6,186
  • 1
  • 23
  • 29
0

TinyThread is tiny.

In additional to including the headers, you just add the TinyThread.cpp to your project or ensure that it builds as part of your project.

The particular error happened to me in VC++ until I added the CPP file to my project.

The thread class and methods were not getting compiled otherwise.

HerbM
  • 521
  • 6
  • 14