【发布时间】:2023-03-28 05:02:01
【问题描述】:
为了使用 OpenCL 而重新学习 C++。我创建了一个名为 CheckDevice 的 Helper 类,它有一堆用于获取设备统计信息的样板代码。
CheckDevice.h
class Utils
{
public:
Utils(){};
~Utils(){};
template<class T>
static bool IsNull(T Object, char* name);
private:
};
CheckDevice.cpp
cl_command_queue Utils::CreateCommandQueue(cl_context context, cl_device_id *device)
{
cl_int err;
cl_device_id *devices;
cl_command_queue queue = NULL;
size_t deviceBufferSize = -1;
cl_kernel kernel = 0;
Utils::IsNull<cl_command_queue>(queue, "Utils::CreateCommandQueue::queue");
return queue;
}
main.cpp
void main()
{
cl_kernel kernel = 0;
Utils::IsNull<cl_kernel>(kernel, "clCreateKernel");
}
问题是从 CheckDevice.cpp 中调用函数 Utils::IsNull 时它工作正常,但是从 main.cpp 调用时,我在 Visual Studios 2012 中得到以下结果
错误 LNK2019:在函数_main 1>C:\Users\Suri\Documents\Visual Studio 2012\Projects\HelloWorld\Debug\HelloWorld.exe : 致命错误 LNK1120: 1 unresolved externals
任何帮助将不胜感激
【问题讨论】:
-
void main()应该是int main()。无论您使用什么书或教程,都不应该告诉您void main()是正确的,并且您的编译器应该警告您。买一本更好的书,并在你的编译器中启用警告。
标签: c++ templates visual-studio-2012