1

I've been trying to use OpenCL in a C++ file. When I try to compile it, it gives a lot of LNK2019 errors, such as :

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)

The Platform class is defined in cl.hpp, and it uses clGetPlatformIds, defined in cl.h but not implemented. I think that is the problem. How can I make the code work ? (I have 24 unresolved external symbols)

VP.
  • 15,509
  • 17
  • 91
  • 161
oranjules
  • 23
  • 1
  • 4
  • "Unresolved external symbol" means it can't find that symbol; have you got the right project settings to link to the external library? Also, would be helpful to know what compiler/toolchain you're using so we can advise you better. – Mike P Jun 17 '15 at 10:23

1 Answers1

5

LNK2019 is a Microsoft Visual Studio error. Add line #pragma comment(lib, "OpenCL.lib") to your source. You also should specify path to the library file in the project options: Project/ Properties/ Configuration Properties / VC++ Directories / Library Directories

Ari0nhh
  • 5,720
  • 3
  • 28
  • 33
  • Thank you, I did not add the pragma line, and the library file was only in the Linker options. – oranjules Jun 17 '15 at 15:01
  • For me the library path was C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\lib\x64 – ProfNimrod Mar 08 '16 at 22:10
  • 1
    This answer turned out to be insufficient in my case. I was also trying to link with OpenCL.lib, and I couldn't get the right symbols out of it. The root of the problem turned out to be that I was building for an x86 target whereas the .lib file had been built for an x64 target, or something like that. I went into my Linker/Librarian options for each project involved, and also into the Configuration Manager, and in those two places I changed every relevant option from x86 to x64, or from Win32 to x64. This removed the linker errors. – mjwach Jan 01 '17 at 20:02