Including OpenCL header with relative path issue in C ++

I am trying to run an OpenCL C ++ sample in Eclipse CTD, which (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 the OpenCL directory (actual path: /System/Library/Frameworks/OpenCL.framework/Versions/A/Headers ), so if I add this path to as the included directory in the project properties and remove the relative OpenCL directory from the #include statement, the link is obviously allowed , but . I notice that in this cl.h file other header files refer to the same relative path (for example, OpenCL/cl_platform.h ), but you can see on the path above this directory OpenCL actually does not exist, so I'm interested how this thing should work in the first place.

My question is:

In my example above, is the OpenCL directory in a relative path that supposedly exists somewhere physically, or it must be some kind of environment variable or similar that points to the actual path in which sdk is installed

Sorry for the confusion, any help appreciated!

Note: from this article on the khronos website, it seems that the OpenCL directory should physically exist.

+5
c ++ c eclipse-cdt opencl macos
source share
2 answers

I recommend that you read the Apple documentation on Frameworks .

The main story, however, is that OS X allows library and header search paths based on the frameworks you compile. For example, to compile a program using the OpenCL SDK on a Macintosh, you must compile it as follows:

 clang -framework OpenCL main.c 

This tells clang (or gcc or llvm-gcc, depending on your choice of compiler) to search for the System OpenCL SDK for both the headers (for compilation) and the libraries (for binding). 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); } 

Please note that here I include OpenCL/opencl.h . This is the preferred title to enable to access CL on Mac. If you look at the title, you will see that it includes cl.h for you as well as cl_platform.h . You can simply enable OpenCL/cl.h if you want; it will still work fine.

+7
source share

According to Khronos specs, a reference to K is a separate file that acts as a wrapper for C ++, also the “.h” at the end of the file means that probably this header is only for C and “maybe” for C ++. Perhaps you can solve this page on this page.

In any case, I found that the Eclipse CDT is really buggy, and it may be worth trying to compile it from the command line, because the MAC OS really does not have a good IDE and, generally speaking, it is not a good OS for developers.

Keep in mind that the only "native" language for MAC is Objective-C, and all others, if any, are portable; if you plan to develop some important projects, I would suggest considering switching to Windows or Linux, because even Linux offers a better development environment than MAC OSX.

Edit 1: here is an example I found, it uses the binding described on the Khronos page, that I just linked the link example 2

Edit 2: you can try 2 things - reinstalling the VGA drivers that usually contain the proper OpenCL SDK for your computer (Intel also offers an SDK, but only works on the iCore processor and some C2Ds) - to compile from the command line

But at this point, your best companions could be Xcode and the online documentation for OpenCL under the MAC link (note that the MAC includes the default 1.0 version of the OpenCL library by default) simply because Xcode offers some better support for such a project under the MAC, and you You can find many tutorials on the Internet using this IDE.

+2
source share

All Articles