我正在尝试在我的 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 上运行的任何想法?
最佳答案
程序很好。您必须链接到必需的 OpenCL 框架。将以下内容添加到 Makefile 中的 cc
命令:
-framework OpenCL
所以 cc
调用看起来像:
cc dumpcl.c -o dumpcl -framework OpenCL
关于尝试在 Mac 上确定支持 OpenCL 的设备时出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20389345/