编译 OpenCL 文件时出现许多 LNK2019 错误

Many LNK2019 errors when compiling OpenCL file

我一直在尝试在 C++ 文件中使用 OpenCL。当我尝试编译它时,它给出了很多 LNK2019 错误,例如:

unresolved external symbol _clGetPlatformIDs@12 referenced in function "public: static int __cdecl cl::Platform::get(class std::vector > *)" (?get@Platform@cl@@SAHPAV?$vector@VPlatform@cl@@V?$allocator@VPlatform@cl@@@std@@@std@@@Z)

Platformclass在cl.hpp中定义,它使用clGetPlatformIds,在cl.h中定义但未实现。我认为这就是问题所在。我怎样才能使代码工作? (我有24个未解析的外部符号)

LNK2019 是 Microsoft Visual Studio 错误。将行 #pragma comment(lib, "OpenCL.lib") 添加到您的来源。您还应该在项目选项中指定库文件的路径:Project/ Properties/ Configuration Properties / VC++ Directories / Library Directories