質問

I am trying to get the details of OpenCL capable devices on my MacMini.

When I compile

// clang -framework OpenCL dumpcl.c -o dumpcl && ./dumpcl

# include <stdio.h>
# include <stdlib.h>
# include <OpenCL/opencl.h>


int main(int argc, char* const argv[]) {
    cl_uint num_devices, i;
    clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);

    cl_device_id* devices = calloc(sizeof(cl_device_id), num_devices);
    clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);

    char buf[128];
    for (i = 0; i < num_devices; i++) {
        clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 128, buf, NULL);
        fprintf(stdout, "Device %s supports ", buf);

        clGetDeviceInfo(devices[i], CL_DEVICE_VERSION, 128, buf, NULL);
        fprintf(stdout, "%s\n", buf);
    }

    free(devices);
}

I get the following error:

make dumpcl
cc     dumpcl.c   -o dumpcl
Undefined symbols for architecture x86_64:
  "_clGetDeviceIDs", referenced from:
      _main in dumpcl-30pmXI.o
  "_clGetDeviceInfo", referenced from:
      _main in dumpcl-30pmXI.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [dumpcl] Error 1

Any ideas how I could modify this program so that it runs on a MacMini running OSX 10.8.5?

役に立ちましたか?

解決

The program is fine. You must link with the requisite OpenCL framework. Add the following to the cc command in the Makefile:

-framework OpenCL

So that the cc invocation looks like:

cc dumpcl.c -o dumpcl -framework OpenCL
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top