如何让gcc中的链接器识别OpenCL库函数?

Der*_*ick 3 xcode gcc makefile opencl

我正熟悉OpenCL.不过,我确定这个问题不是OpenCL特有的.

我的主文件的顶部看起来像:

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

// some code

cl_device_id device_id; //declaring a device id gives no errors

int err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);
//the above API call does give an error.
Run Code Online (Sandbox Code Playgroud)

我在Snow Leopard上这样做.我可以使用XCode构建和运行Apple的示例.我也可以通过运行make来编译和运行NVIDIA的示例代码.

如何在不使用XCODE的情况下正确编译代码?

Der*_*ick 8

$ gcc -framework OpenCL hello.c
Run Code Online (Sandbox Code Playgroud)

$ gcc -framework opencl hello.c
Run Code Online (Sandbox Code Playgroud)

都工作.有人想在非OSX环境下试试吗?