Problem Including OpenCL library

Hi,

I'm having what is probably a really basic silly problem but Google has failed me and I really want to figure this out.

I'm learning OpenCL and trying to write just a basic "hello world" with it in C++. I have all my code in main.cpp for now. I have these headers included:
1
2
3
4
5
6
7
8
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <iostream>
#include <vector>
#include "CL/cl.hpp" 


when I compile with:
g++ main.cpp -o test.bin

it throws this error:

main.cpp:105:11: error: expected type-specifier
     catch(cl::Error err){
           ^


at this place in the code:
1
2
3
4
5
6
7
    cl::CommandQueue queue;
    try{
        queue = cl::CommandQueue(context, devices[deviceUsed], 0, &err);
    }
    catch(cl::Error err){
        printf("ERROR: %s(%d)\n", err.what(), err.err());
    }


The error seems to be indicating that it can't find the correct headers or libraries, but it's not throwing an error a couple lines before with cl::CommandQueue. So what's up? Is it finding the library or not? I checked the header cl.hpp and both cl::CommandQueue and cl::Error are in there, and I'm assuming their both in libOpenCL. If it can find one and doesn't throw an error, then why is it throwing an error on the other? Again this is probably a really stupid question but I am clueless.

Thanks in advance!
Try putting
#define __CL_ENABLE_EXCEPTIONS
before including cl.hpp.
Wow, yup that fixed it. I didn't even think about the directives. Thanks a bunch!
Topic archived. No new replies allowed.