1

I have done some CUDA programming at Windows and now I want to learn OpenCL. I have Macbook retina which contains Intel Iris graphics card. I already have xCode. I tried to find a lot at internet about how can I check if OpenCL is already installed at my Mac but I could not understand a proper way. I just read that Macbook will automatically get OpenCL installed with xCode.

I wrote few lines which are related to OpenCL but it throws error:

Undefined symbols for architecture x86_64:
  "_clGetPlatformIDs", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am completely new to OpenCL and unable to understand how things work with OpenCL.

My Code:

#ifdef __APPLE__
#include "OpenCL/opencl.h"
#else
#include "CL/cl.h"
#endif

#include <iostream>
using namespace std;

int main()
{
    cl_uint platformIdCount = 0;
    clGetPlatformIDs (0, nullptr, &platformIdCount);

    cout<<"Test openCL";
    return 0;
}

PS: Inclusion of header files does not throw any error. The error occurs due to clGetPlatformIDs() in the main().

jprice
  • 9,755
  • 1
  • 28
  • 32
user2756695
  • 676
  • 1
  • 7
  • 22

1 Answers1

4

You need to link against the OpenCL framework. This involves adding -framework OpenCL to your command-line, or if you're using Xcode adding OpenCL.framework to the Link Binary With Libraries section in Build Phases.

jprice
  • 9,755
  • 1
  • 28
  • 32
  • with your suggestion, there is no error for the code which I mentioned in my post but the sample code at SO ( `http://stackoverflow.com/a/7898347/2386113` ) is still throwing an error for `cl_device_id* devices = calloc(sizeof(cl_device_id), num_devices);`. The error say: `Cannot initialize a variable of type cl_device_id` – user2756695 Sep 09 '15 at 19:46
  • If you read the whole error message, it will tell you that you are assigning a `void*` to a `cl_device_id*`. Just cast the result of the `calloc` call to a `cl_device_id*`. – jprice Sep 09 '15 at 19:57