我建议您阅读 Apple 的文档构架 http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WhatAreFrameworks.html.
然而,基本的情况是,OS X 根据您编译的框架来解析库和标头搜索路径。例如,要在 Macintosh 上使用 OpenCL SDK 编译程序,您可以像这样编译:
clang -framework OpenCL main.c
这告诉 clang(或 gcc、或 llvm-gcc,具体取决于您选择的编译器)在系统 OpenCL SDK 中搜索标头(用于编译)和库(用于链接)。试一试:
// compile me with: clang -framework OpenCL -o test test.c
#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);
}
请注意,我已经包括OpenCL/opencl.h
这里。这是在 Mac 上访问 CL 时首选包含的标头。如果你看一下标题,你会发现它包括cl.h
为你,以及cl_platform.h
。你可以只包含OpenCL/cl.h
如果你愿意的话;它仍然可以正常工作。