My programming experience is about 1 year of C/C++ experience from high school, but I did my research and wrote a simple program with OpenCL a few months ago. I was able to compile and run this on an Apple computer relatively easily with g++ and the --framework option. Now I'm on my Ubuntu machine and I have no idea how to compile it. The correct drivers have been downloaded along with ATI's Stream SDK (I have an ATI Radeon HD5870). Any help would be appreciated!
-
NVIDIA: http://stackoverflow.com/questions/7542808/what-is-needed-to-compile-opencl-on-ubuntu-and-by-extension-opencl-period/33483311#33483311 – Ciro Santilli OurBigBook.com Nov 02 '15 at 17:21
3 Answers
Try
locate libOpenCL.so
If it is in one of the standard directories (most likely /usr/lib, or /usr/local/lib) you need to replace "--framework OpenCL" with "-lOpenCL". If g++ cannot find the lib you can tell g++ to look in a specific directory by adding "-L/path/to/library".
I wish I had my Linux to be more helpful... It is probably best if you redownload the ati-stream-sdk, after extracting it, open the Terminal and "cd /path/to/extracted/files"; in that directory execute make && sudo make install
make
you probably know this from windows, this compiles, whatever needs to be compiled&&
chains commands together, the following commands will only be executed if the first command succeededsudo make install
this will put the files in the expected places (sudo executes a command with superuser priviledges, you will have to enter your password)
Hope that helps.

- 3,852
- 18
- 30
-
I've tried this, but then I get the error "fatal error: CL/opencl.h: No such file or directory" (one of the things that I #included in my program). – user492268 Oct 30 '10 at 20:56
-
1maybe you need to tell g++ about the location of the "CL/" directory (you do this with a "dash capital i"): g++ -L/path/to/library -I/path/to/CL main.cpp -lOpenCL – bjoernz Oct 30 '10 at 21:00
-
Now I'm getting: /usr/bin/ld: cannot find -lOpenCL collect2: ld returned 1 exit status. Maybe I should be asking whether I am supposed to have moved around files from the SDK folder into different parts of my filesystem. I apologize, I am new to Linux (just recently trying to switch from Windows). – user492268 Oct 30 '10 at 21:07
-
And she compiles and runs! Unfortunately, I wrote this when OpenCL was still in the beta...so apparently some code changes are needed. Thanks for the help! – user492268 Oct 30 '10 at 22:29
-
3Oh, and in case anyone is in a similar position, the final line to compile was: "g++ -lOpenCL -L/stream-sdk-2.2/lib/x86_64/ -I/stream-sdk-2.2/include/ [file_name].c" – user492268 Oct 30 '10 at 22:30
-
3I had to run `g++ -L/opt/AMDAPP/lib/x86_64/ -I/opt/AMDAPP/include [filename.cpp] -lOpenCL` – Benjamin Manns Sep 14 '12 at 14:11
You might be missing the dynamic libraries from the dynamic linker configuration.
Search for where the libraries are. Most likely /usr/lib, or /usr/local/lib.
Make sure the path location is also configured at one of these places:
- LD_LIBRARY_PATH - you can set it in you environment shell, like .bashrc
- /etc/ld.so.conf - you will need to call ldconfig to update the cache and it requires root access to change the file.

- 632
- 4
- 10
Reason
Aside from @bjoernz, my system can't find the libOpenCL.so
file
It's because the correct file directory is missing
After searchig over the internet, I found out that libOpenCL.so
file can provided by ocl-icd-opencl-dev
package
Solution
You just need to install the package mentioned above by typing into cmd
sudo apt update
sudo apt install ocl-icd-opencl-dev
Therefore, libOpenCL.so
can be found under /usr/lib/x86_64-linux-gnu/
folder
My System Information
- OS: Ubuntu 16.04 LTS
- GPU: NVIDIA GeForce GTX 660
- GPU Driver: nvidia-375
- OpenCL: 1.2
Reference:

- 1,837
- 2
- 22
- 33