23

I have sample "Hello, World!" code from the net and I want to run it on the GPU on my university's server. When I type "gcc main.c," it responds with:

CL/cl.h: No such file or directory

What should I do? How can I have this header file?

Jamal
  • 763
  • 7
  • 22
  • 32
sandra
  • 949
  • 3
  • 12
  • 25
  • Probable duplicate http://stackoverflow.com/questions/4872143/cl-h-not-found-how-to-link-in-makefile – Meluha Jan 23 '14 at 08:42
  • https://stackoverflow.com/questions/7542808/what-is-needed-to-compile-opencl-on-ubuntu-and-by-extension-opencl-period – Adam Sep 22 '17 at 19:58

2 Answers2

27

Are you using Ubuntu or Debian distro? Then you could use this package to solve the problem with missing header file:

apt-get install opencl-headers

You must install opencl library to solve linking issues using that Debian and Ubuntu package:

apt-get install ocl-icd-libopencl1

You can also use these nonfree libraries: nvidia-libopencl1 (Debian) or nvidia-libopencl1-xx (Ubuntu).

OscarGarcia
  • 1,995
  • 16
  • 17
  • This is a quick fix without messing with `CFLAGS` or whatever (for example when running `python setup.py build/install` on something which requires `pyopencl`. But you will still need to set `LDFLAGS` if the libOpenCL.so is not on the default path. – Tomasz Gandor Jan 02 '18 at 08:02
  • 1
    Of course. I'm using `opencl-headers` and `ocl-icd-libopencl1`, the library path is `/usr/lib/x86_64-linux-gnu/libOpenCL.so.1.0.0`, so changing `LDFLAGS` it is not necessary with this package. I'll update my answer, thanks for the comment. – OscarGarcia Jan 02 '18 at 08:33
  • 1
    This solved the issue to allow for LightGBM installation on GPU using make – Camron_Godbout Jan 15 '20 at 22:13
23

Make sure you have the appropriate toolkit installed.

This depends on what you intend running your code on. If you have an NVidia card then you need to download and install the CUDA-toolkit which also contains the necessary binaries and libraries for opencl.

Are you running Linux? If you believe you already have OpenCL installed it could be that it is found at a different location than the standard /usr/include. Type the following and see what results you get:

find / -iname cl.h 2>/dev/null

On my laptop for example, the header is found at /usr/local/cuda-5.5/include. If its the case were your header file is at a different location you simply have to specify the path during complication

g++ -I/usr/local/cuda-5.5/include main.c -lOpenCL

Alternatively, you can create a symbolic link from the path to /usr/include:

ln -s /usr/local/cuda-5.5/include/CL /usr/include
Michael Aquilina
  • 5,352
  • 4
  • 33
  • 38