Ubuntu 16.04下编译OpenCL 1.2示例时头文件找不到的问题
Hey there, I’ve run into this exact headache before with AMD GPUs on older Ubuntu releases—let’s work through it step by step. Even though you’ve installed the required packages, GCC might not be looking in the right spot for the OpenCL headers. Here’s how to sort it out:
First, track down where your
cl.hppfile actually lives
Run this command to find the exact path of the missing header:find /usr /opt -name "cl.hpp"On Ubuntu 16.04 with AMD’s Radeon drivers, this will likely turn up something like
/opt/amdgpu-pro/include/CL/cl.hppor/usr/include/CL/cl.hpp.Compile with an explicit include path
If the header is in a directory GCC doesn’t check by default (like/opt/amdgpu-pro/include), tell GCC where to look using the-Iflag. For example:g++ test.cpp -lOpenCL -I/opt/amdgpu-pro/includeSwap the path with whatever you found in the previous step.
Permanently fix the include path (optional)
If you don’t want to type the-Iflag every time, add the header directory to your C++ include path environment variable:echo 'export CPLUS_INCLUDE_PATH=/opt/amdgpu-pro/include:$CPLUS_INCLUDE_PATH' >> ~/.bashrc source ~/.bashrcNow you can compile with your original command
g++ test.cpp -lOpenCLwithout extra flags.Double-check your package installation
Just to be thorough, verify thatopencl-headersactually installed the header file:dpkg -L opencl-headers | grep cl.hppIf this returns nothing, re-install the package with:
sudo apt-get install --reinstall opencl-headers
Another quick fix if the header is in a non-standard location is to create a symbolic link to /usr/include (GCC’s default include directory):
sudo ln -s /opt/amdgpu-pro/include/CL /usr/include/CL
This lets GCC find the headers automatically without extra flags.
内容的提问来源于stack exchange,提问作者Luke Naylor

