我在OS X 10.7 Lion上安装了所有的开发工具,但是当我在一个相对简单的程序上运行GCC时,只需要对clCreateProgramFromSource之类的openCL函数进行几次调用,我得到以下错误列表:
Undefined symbols for architecture x86_64: "_CreateContext",referenced from: _build_kernel in ccFuZYMI.o "_GetDevices",referenced from: _build_kernel in ccFuZYMI.o "_CreateCommandQueue",referenced from: _build_kernel in ccFuZYMI.o "_clCreateProgramWithSource",referenced from: _build_kernel in ccFuZYMI.o "_clBuildProgram",referenced from: _build_kernel in ccFuZYMI.o "_clCreateKernel",referenced from: _build_kernel in ccFuZYMI.o "_clCreateBuffer",referenced from: _build_kernel in ccFuZYMI.o "_clEnqueueWriteBuffer",referenced from: _sync_run_kernel in ccFuZYMI.o "_clSetKernelArg",referenced from: _sync_run_kernel in ccFuZYMI.o "_clEnqueueNDRangeKernel",referenced from: _sync_run_kernel in ccFuZYMI.o "_clEnqueueReadBuffer",referenced from: _sync_run_kernel in ccFuZYMI.o "_clReleaseContext",referenced from: _destroy_kernel in ccFuZYMI.o "_clReleaseCommandQueue",referenced from: _destroy_kernel in ccFuZYMI.o "_clReleaseMemObject",referenced from: _destroy_kernel in ccFuZYMI.o "_clReleaseProgram",referenced from: _destroy_kernel in ccFuZYMI.o "_clReleaseKernel",referenced from: _destroy_kernel in ccFuZYMI.o ld: symbol(s) not found for architecture x86_64
还有一些其他警告,但在计算阶段没有其他错误.这是(如果不清楚)链接器错误.它似乎能够在创建目标文件时看到头文件中的定义,因为它给了我关于不兼容指针类型的警告.
我曾尝试粘贴到xcode项目中,但我得到了完全相同的错误.我试过only other OS X Lion / OpenCL result’s solution,但没有用.
解决方法
看起来你错过了OpenCL框架 – 试试:
$gcc -Wall foo.c -framework OpenCL -o foo