OpenCL header inclusion with relative path issue in C++

后端 未结 2 1123
抹茶落季
抹茶落季 2021-02-09 20:24

I am trying to run an OpenCL C++ sample on Eclipse CTD that (on Mac) includes the OpenCL header as follows:

#include 

The fi

相关标签:
2条回答
  • 2021-02-09 21:06

    According to Khronos specifications link to K there is a separate file that act as a wrapper for the C++, also the ".h" at the end of the file means that probably this header is only for the C and "maybe" for the C++. Probably you can solve this reading that page.

    Anyway i found the Eclipse CDT really buggy and maybe it's worth trying to compile from the command line because the MAC OS environment really lacks of a good IDE and generally speaking it's not a good OS for developers.

    Keep in mind that the only "native" language for the MAC is the Objective-C and all the others, if present, are porting; if you plan to develop some important projects i would suggest to consider a switch to Windows or Linux because even Linux offer a better environment for the developers compared to MAC OSX.

    Edit 1: here is an example that i found, it use the binding described in the Khronos page that i just linked link 2 example

    Edit 2: you can try 2 things - re-installing the VGA drivers that usually contain the proper OpenCL SDK for you machine ( Intel also offers an SDK but it runs only on iCore CPU and some C2D ) - to compile from the command line

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

    0 讨论(0)
  • 2021-02-09 21:27

    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:

    clang -framework OpenCL main.c
    

    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);
    }
    

    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.

    0 讨论(0)
提交回复
热议问题