0

I am currently using the following guide to try to get a basic OpenCL example working in a Windows environment: https://github.com/KhronosGroup/OpenCL-Guide/blob/main/chapters/getting_started_windows.md

However, I'm hitting a snag in the compilation step.

I use the following command from a Developer Powershell for VS2022:

cl.exe /nologo /TC /W4 /DCL_TARGET_OPENCL_VERSION=100 /IC:\src\vcpkg\installed\x64-windows\include\ Main.c /Fe:HelloOpenCL /link /LIBPATH:C:\src\vcpkg\installed\x64-windows\lib OpenCL.lib

(I tried to use theirs with <VCPKGROOT>, but that did not work despite setting it in the environment variables, so not sure if that's a problem)

However, when I try this command, I get the following error:

Main.c
Main.obj : error LNK2019: unresolved external symbol _clGetPlatformIDs@12 referenced in function _main
C:\src\vcpkg\installed\x64-windows\lib\OpenCL.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
HelloOpenCL.exe : fatal error LNK1120: 1 unresolved externals

That seems to suggest that OpenCL's library is an X64 library, while cl.exe is trying to make an X86 executable. However, when I try adding /MACHINE:X64 to the arguments, I get the exact same error.

What am I doing wrong?

EDIT with answer: The instructions linked do not make the situation with cl.exe very clear.

If you use "Developer Command Prompt for VS2022" or "Developer Powershell for VS2022", neither will work as they both are set for the X86 version of Cl.exe.

In order to actually make it work, you need to use the vcvarsall batch script, like so, from another shell:

"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64

That will launch regular shell (not powershell, sadly) with all the visual studio development variables, and for X64.

Tyler Shellberg
  • 1,086
  • 11
  • 28
  • There are several different `cl.exe` installed in different folders. One for x86, one for x64 – vvv444 May 23 '23 at 19:07

0 Answers0