I created a class, ProcessQueue
:
//ProcessQueue.h
template<class T>
class ProcessQueue{
public:
void addTask(T param);
void clearQueue();
void addSetup(void (*setup)());
void addProcess(void (*process)(T));
void addCleanup(void (*cleanup)());
void setup();
void finish();
private:
//Some private fields and functions that aren't relevant
}
addSetup
and addCleanup
add functions that are performed when setup
and finish
are called (The function pointers are then stored in a vector
, but that shouldn't matter). addProcess
should accept a void
function that inputs a variable of type T
, and addTask
adds a variable of type T
to a processing queue.
When clearQueue
is called, the class iterates over each T
that has been added and calls the various "process" functions that have been added to the ProcessQueue
.
In another file (kernel.cu
), I use a ProcessQueue to process the results of a computation:
(Note that this is part of the host
code of the cu
file, so it is regular C++. runRecord
is simply a c-style struct
)
//kernel.cu
ProcessQueue<runRecord> queue;
#ifdef PRINTTOFILE
queue.addSetup(setupPrintToFile);
queue.addProcess(processPrintToFile);
queue.addCleanup(cleanupPrintToFile);
#endif
#ifdef PRINTRESULTS
queue.addProcess(printRecord);
#endif
queue.setup();
//Do some computation
//Add the results to the ProcessQueue
queue.clearQueue();
queue.finish();
Some other function declarations that may be relevant:
//Various .h files
void setupPrintToFile();
void processPrintToFile(runRecord r);
void cleanupPrintToFile();
void printRecord(runRecord rec);
When I compile this, I get a few error messages:
1>kernel.cu.obj : error LNK2001: unresolved external symbol "public: void __thiscall ProcessQueue<struct runRecord>::addTask(struct runRecord)" (?addTask@?$ProcessQueue@UrunRecord@@@@QAEXUrunRecord@@@Z)
1>kernel.cu.obj : error LNK2001: unresolved external symbol "public: void __thiscall ProcessQueue<struct runRecord>::clearQueue(void)" (?clearQueue@?$ProcessQueue@UrunRecord@@@@QAEXXZ)
1>kernel.cu.obj : error LNK2001: unresolved external symbol "public: void __thiscall ProcessQueue<struct runRecord>::addSetup(void (__cdecl*)(void))" (?addSetup@?$ProcessQueue@UrunRecord@@@@QAEXP6AXXZ@Z)
1>kernel.cu.obj : error LNK2001: unresolved external symbol "public: void __thiscall ProcessQueue<struct runRecord>::addProcess(void (__cdecl*)(struct runRecord))" (?addProcess@?$ProcessQueue@UrunRecord@@@@QAEXP6AXUrunRecord@@@Z@Z)
1>kernel.cu.obj : error LNK2001: unresolved external symbol "public: void __thiscall ProcessQueue<struct runRecord>::addCleanup(void (__cdecl*)(void))" (?addCleanup@?$ProcessQueue@UrunRecord@@@@QAEXP6AXXZ@Z)
1>kernel.cu.obj : error LNK2001: unresolved external symbol "public: void __thiscall ProcessQueue<struct runRecord>::finish(void)" (?finish@?$ProcessQueue@UrunRecord@@@@QAEXXZ)
fatal error LNK1120: 6 unresolved externals
I'm not too sure where the problem is. I've tried changing the template and function declarations, but it doesn't seem to help.
The compiler is nvcc v7.5.