C++ OpenCL API fails to find platforms

I am trying to utilize the C++ API for OpenCL. I have installed my NVIDIA drivers and I have tested that I can run the simple vector addition program provided on 'thebigblob’s ‘getting started with opencl’ post. I can compile this program with following gcc call and the program runs without problem.

gcc main.c -o vectorAddition -l OpenCL -I/usr/local/cuda-7.0/include

However, I would very much prefer to use the C++ API as opposed the very verbose host files needed for C.

I downloaded the C++ bindings from Khronos (version 1.1) and placed the cl.hpp file in the same location as my other cl.h file. I then tried the code provided in the ‘Intro to OpenCL tutorial’. I set LD_LIBRARY_PATH = /usr/local/cuda-7.0/lib64 and copiled with the following call.

g++ lesson1.cpp -o hello_world -l OpenCL -I/usr/local/cuda-7.0/include

It compile fine but when I try and run ./hello_world I receive the following error:

ERROR: cl::Platform::get (-1)

Have I missed something?

I can’t figure how to edit my original post so here is an update regarding this problem.

I learned that my graphics card cannot use the most recent NVIDIA driver so I purged and installed the nvidia-340 drivers. I then installed cuda-6.5 which is compatible with the nvidia-340 driver. Modifying the initial compilation above it is now:

gcc main.c -o vectorAddition -l OpenCL -I/usr/local/cuda-6.5/include

Again this compiles but I also modified it to return the number of platforms found which strangely returns 0. Have I missed something here that my code cannot find my graphics card?

My workflow from clean install:

  1. sudo apt-get install nvidia-340
  2. Download 6.5 cuda .run file and install (skipping driver install)
  3. Update PATH and LD_LIBRARY_PATH environmental variables
  4. compile main.c and execute

I did manage to solve my problem. It appears necessary to avoid doing any installation with apt-get calls. After purging all cuda and nvidia implementations I reinstalled everything with the cuda run file. This got everything to install correctly and the files compiled and executed correctly.