尝试在mac上确定支持OpenCL的设备时编译错误

时间:2013-12-05 00:56:51

标签: c gpu osx-mountain-lion

我正在尝试在MacMini上获取支持OpenCL的设备的详细信息。

编译时

// 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);
}

我收到以下错误:

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

我是如何修改此程序以便在运行OSX 10.8.5的MacMini上运行的?

1 个答案:

答案 0 :(得分:1)

程序没问题。您必须链接到必需的OpenCL框架。将以下内容添加到Makefile中的cc命令:

-framework OpenCL

以便cc调用如下:

cc dumpcl.c -o dumpcl -framework OpenCL