'Opencl/Gcc error vsc "fatal error: CL/cl.hpp: No such file or directory"

I am having trouble compiling a OpenCL code with two .cl kernel files and a .cpp file, I'm new to C++ but I know you need headers so I've downloaded many eg. OCL_SDK_LIGHT, CUDA, vcpkg OPENCL package. All bring up the same error after compiling and only after compiling here is the error. I'm using the mingw64 g++ compiling which doesn't contain the CL/cl.hpp file, I've tried adding it directly into the include file from other directories but that just brings up more errors. I have also tried compiling in and out of vsc with similar results. I have a nvidia gpu and an amd cpu. I have also added the path to the CUDA toolkit in the properties.json file in vsc.

Any help would be amazing!



Solution 1:[1]

You have to tell the compiler where the CL/cl.hpp file is located. I usually copy the folder containing the OpenCL headers in the project directory. Then compile with:

g++ *.cpp -o Test.exe -I./OpenCL/include -L./OpenCL/lib -lOpenCL

Once you have the OpenCL headers, there is no need to install any SDK or CUDA. The graphics driver alone is sufficient as it contains the OpenCL Runtime.


For an easy start with OpenCL development, I recomment this OpenCL-Wrapper. It contains a vector addition example. The Wrapper vastly simplifies working OpenCL and entirely eliminates code overhead.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ProjectPhysX