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>
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.
My question:
In my example above, is the ‘OpenCL’ directory in the relative path supposed to exist physically somewhere or is it supposed to be some kind of environment variable or similar that points to the actual path the sdk is installed in?
Sorry for the confusion, any help appreciated!
Note: from this article on the khronos website it seems that the OpenCL directory is supposed to physically exist.
I recommend you read Apple’s documentation on Frameworks.
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:
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:
Note that I’ve include
OpenCL/opencl.hhere. 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 includescl.hfor you, as well ascl_platform.h. You can just includeOpenCL/cl.hif you’d like; it will still work fine.