Can someone tell me why this doesn't compile?
Thanks in advance for any and all help.
- Code: Select all
#include <iostream>
#include <deque>
#include "Poco/Runnable.h"
#include "Poco/ThreadPool.h"
using namespace std;
class Task : public Poco::Runnable {
private:
int _id;
public:
Task() {};
void setId(int x) { _id = x; }
void run(){
for (int i= 0; i < 100; i++){
cout << i << ") Task " << _id << " is working" << std::endl;
}
}
};
int main(){
Task *ptr = NULL;
deque<Task> DT;
deque<Task>::iterator iter;
Poco::ThreadPool pool;
for(int i = 0; i < 10; i++) {
ptr = new Task();
ptr->setId(i);
DT.push_back(*ptr);
delete(ptr);
ptr = NULL;
}
for(iter = DT.begin(); iter != DT.end(); iter++) pool.start(*iter);
pool.joinAll();
return 0;
}
Here is the compile error I get:
- Code: Select all
$ g++ -O2 -Wall -static -I./poco.lib/include -L./poco.lib/lib -lPocoFoundation learnPoco.cpp -o learnPoco.exe
/tmp/ccKMn21d.o: In function `main':
learnPoco.cpp:(.text+0xe3): undefined reference to `Poco::ThreadPool::ThreadPool(int, int, int, int)'
learnPoco.cpp:(.text+0x143): undefined reference to `Poco::Runnable::Runnable()'
learnPoco.cpp:(.text+0x231): undefined reference to `Poco::ThreadPool::start(Poco::Runnable&)'
learnPoco.cpp:(.text+0x25b): undefined reference to `Poco::ThreadPool::joinAll()'
learnPoco.cpp:(.text+0x263): undefined reference to `Poco::ThreadPool::~ThreadPool()'
learnPoco.cpp:(.text+0x389): undefined reference to `Poco::ThreadPool::~ThreadPool()'
/tmp/ccKMn21d.o: In function `Task::~Task()':
learnPoco.cpp:(.text._ZN4TaskD2Ev[_ZN4TaskD5Ev]+0x8): undefined reference to `Poco::Runnable::~Runnable()'
/tmp/ccKMn21d.o: In function `Task::~Task()':
learnPoco.cpp:(.text._ZN4TaskD0Ev[_ZN4TaskD5Ev]+0xc): undefined reference to `Poco::Runnable::~Runnable()'
/tmp/ccKMn21d.o:(.rodata._ZTI4Task[typeinfo for Task]+0x10): undefined reference to `typeinfo for Poco::Runnable'
collect2: ld returned 1 exit status
I'm sorry if this is a newbie question but I'm pulling my hair out trying to figure this one out.
The tutorials all suggest that I haven't made a mistake (or at least not one I can see).
I seem to have to define a constructor and destructor for both ThreadPool and Runnable??





