问题描述
我试图在Eclipse上的CTD(在Mac上)运行的OpenCL C ++样本包括OpenCL的标题如下:
I am trying to run an OpenCL C++ sample on Eclipse CTD that (on Mac) includes the OpenCL header as follows:
#include <OpenCL/cl.h>
文件存在我的系统上(OpenCL的SDK默认情况下,在Mac上安装),但不是在OpenCL的目录(实际路径: /System/Library/Frameworks/OpenCL.framework/Versions/A/头
),所以如果我再补充一点路径作为项目的属性包含的目录,并从的#include
语句相对的OpenCL目录链接显然是解决的但我注意到在<一个href=\"http://www.google.ie/url?sa=t&rct=j&q=cl.h&source=web&cd=1&ved=0CBkQFjAA&url=http://www.khronos.org/registry/cl/api/1.0/cl.h&ei=U-O5TtqwAsenhAfK9by2Bw&usg=AFQjCNFd2sx39EsHLfrlxHNbAwTGudOLBw&sig2=bz8Aa9Q7CWtJIR_ahjWECw\"相对=nofollow>该cl.h文件其他头文件使用相同的相对路径引用(例如的OpenCL / cl_platform.h
),但你可以从上面这个路径看的的OpenCL 的目录实际上并不存在,所以我想知道这件事情应该是怎样摆在首位的工作。
The file exists on my system (OpenCL sdk is installed by default on Mac) but not in a OpenCL directory (actual path: /System/Library/Frameworks/OpenCL.framework/Versions/A/Headers
), so if I add that path as an included directory in the properties of the project and remove the relative OpenCL directory from the #include
statement the linking is obviously resolved but I notice that in that cl.h file other header files are referenced with the same relative path (ex. OpenCL/cl_platform.h
) but you can see from the path above this OpenCL directory does not actually exist so I am wondering how this thing is supposed to work in the first place.
我的问题:
在我上面的例子中,与OpenCL的中的相对路径的目录应该在物理上的某处存在,或者它应该是某种环境变量或类似的指向SDK安装在实际的路径
很抱歉的混乱,任何帮助AP preciated!
Sorry for the confusion, any help appreciated!
请注意:从似乎OpenCL的目录应该是物理存在。
Note: from this article on the khronos website it seems that the OpenCL directory is supposed to physically exist.
推荐答案
我建议你在Frameworks.
基本的故事,然而,就是OS X解析基础上编译对框架库和头搜索路径。例如,要编译使用OpenCL的SDK在Macintosh上的程序,你会编这样的:
The basic story, however, is that OS X resolves library and header search paths based on the frameworks you compile against. For example, to compile a program using the OpenCL SDK on a Macintosh, you'd compile like this:
clang -framework OpenCL main.c
这告诉铛(或GCC,LLVM或-GCC,根据您选择的编译器)来搜索系统OpenCL的SDK为标题(编译)和库(链接)。试试看:
This tells clang (or gcc, or llvm-gcc, depending on your choice of compiler) to search the System OpenCL SDK for both headers (for compilation) and libraries (for linking). Give it a try:
// 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
在这里。这是preferred头包括以访问CL在Mac上。如果你看一下标题,你会看到它包含 cl.h
为你,以及 cl_platform.h
。你可以只包括的OpenCL / cl.h
,如果你想;它仍然会正常工作。
Note that I've include OpenCL/opencl.h
here. This is the preferred header to include to get access to CL on the Mac. If you look at the header, you will see that it includes cl.h
for you, as well as cl_platform.h
. You can just include OpenCL/cl.h
if you'd like; it will still work fine.
这篇关于OpenCL的标题包含在C相对路径问题++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!