PDA

View Full Version : Hello world program - compilation error



chomolungma
01-09-2010, 09:14 AM
Hello,

I am new to OpenCL and I've been trying to compile the following piece of code, but with no success

#define __CL_ENABLE_EXCEPTIONS
#define __NO_STD_VECTOR
#define __NO_STD_STRING

#include <CL/cl.hpp>
#include <cstdio>
#include <cstdlib>
#include <iostream>

const char * helloStr = "__kernel void hello(void) { }\n";

int main(void) {
try {
cl::Context context(CL_DEVICE_TYPE_GPU, 0, NULL, NULL, &err);
cl::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
cl::CommandQueue queue(context, devices[0], 0, &err);
cl::Program::Sources source(1, std::make_pair(helloStr,strlen(helloStr)));
cl::Program program_ = cl::Program(context, source);
program_.build(devices);
cl::Kernel kernel(program_, "hello", &err);
cl::KernelFunctor func = kernel.bind(queue, cl::NDRange(4, 4), cl::NDRange(2, 2));
func().wait();
} catch (cl::Error err) {
std::cerr << "ERROR: " << err.what() << "(" << err.err() << ")" << std::endl;
}
return EXIT_SUCCESS;
}


I've got the following errors:


/usr/include/CL/cl.hpp:3367: error: ‘pair’ is not a member of ‘cl::std’
/usr/include/CL/cl.hpp:3367: error: ‘pair’ is not a member of ‘cl::std’
/usr/include/CL/cl.hpp:3367: error: template argument 1 is invalid
/usr/include/CL/cl.hpp:3367: error: expected unqualified-id before ‘>’ token
/usr/include/CL/cl.hpp:3368: error: ‘pair’ is not a member of ‘cl::std’
/usr/include/CL/cl.hpp:3368: error: ‘pair’ is not a member of ‘cl::std’
/usr/include/CL/cl.hpp:3368: error: template argument 1 is invalid
/usr/include/CL/cl.hpp:3368: error: expected unqualified-id before ‘>’ token
/usr/include/CL/cl.hpp:3393: error: expected ‘,’ or ‘...’ before ‘&’ token
/usr/include/CL/cl.hpp:3473: error: expected ‘,’ or ‘...’ before ‘&’ token
/usr/include/CL/cl.hpp: In constructor ‘cl::Program::Program(const cl::Context&, int)’:
/usr/include/CL/cl.hpp:3398: error: ‘sources’ was not declared in this scope
/usr/include/CL/cl.hpp:3411: error: ‘err’ was not declared in this scope
/usr/include/CL/cl.hpp: In constructor ‘cl::Program::Program(const cl::Context&, const cl::vector<cl::Device, 10u>&, int)’:
/usr/include/CL/cl.hpp:3478: error: ‘binaries’ was not declared in this scope
/usr/include/CL/cl.hpp:3490: error: ‘binaryStatus’ was not declared in this scope
/usr/include/CL/cl.hpp:3495: error: ‘err’ was not declared in this scope
/usr/include/CL/cl.hpp: At global scope:
/usr/include/CL/cl.hpp:5041: error: ‘cl::std::pair’ has not been declared
/usr/include/CL/cl.hpp:5041: error: expected ‘,’ or ‘...’ before ‘<’ token
/usr/include/CL/cl.hpp: In member function ‘cl_int cl::CommandQueue::enqueueNativeKernel(void (*)(void*), int) const’:
/usr/include/CL/cl.hpp:5049: error: ‘args’ was not declared in this scope
/usr/include/CL/cl.hpp:5050: error: ‘mem_objects’ was not declared in this scope
/usr/include/CL/cl.hpp:5052: error: ‘mem_locs’ was not declared in this scope
/usr/include/CL/cl.hpp:5053: error: ‘events’ was not declared in this scope
/usr/include/CL/cl.hpp:5055: error: ‘event’ was not declared in this scope


My OS is Ubuntu 9.04, the compiler is gcc 4.3.3 and I've got the latest OpenCL headers installed.

Any help is appreciated. Thanks in advance

Adam Simpson
01-09-2010, 09:42 AM
Try changing the order of your includes:


#include <CL/cl.hpp>
#include <cstdio>
#include <cstdlib>
#include <iostream>

to



#include <cstdio>
#include <cstdlib>
#include <iostream>
#include "CL/cl.hpp"


Also you need to define "cl_int err"

chomolungma
01-09-2010, 11:12 AM
Reordering the #include statements fixed the problem. Thank you very much :-)

lsolano
01-28-2010, 10:03 AM
I'm new to opencl too, what is the command line to compile that piece of code please ?

deNorma
02-04-2010, 02:59 PM
g++ yourfile.cpp -L/yourlib -I/yourinc -lOpenCL

buci
02-22-2010, 05:01 PM
Hi, I am new too to OpenCL and, when I try to compile this same "Hello World" example, I get the followings errors:

Error 2 error C2666: 'cl::vector<T>::operator []' : 2 overloads have similar conversions c:\program files (x86)\microsoft visual studio 8\vc\include\cl\cl.hpp 3403
Error 3 error C2228: left of '.first' must have class/struct/union c:\program files (x86)\microsoft visual studio 8\vc\include\cl\cl.hpp 3403
Error 4 error C2666: 'cl::vector<T>::operator []' : 2 overloads have similar conversions c:\program files (x86)\microsoft visual studio 8\vc\include\cl\cl.hpp 3404
Error 5 error C2228: left of '.second' must have class/struct/union c:\program files (x86)\microsoft visual studio 8\vc\include\cl\cl.hpp 3404
Error 6 error C2666: 'cl::vector<T>::operator []' : 2 overloads have similar conversions c:\program files (x86)\microsoft visual studio 8\vc\include\cl\cl.hpp 3483
Error 7 error C2228: left of '.first' must have class/struct/union c:\program files (x86)\microsoft visual studio 8\vc\include\cl\cl.hpp 3483
Error 8 error C2666: 'cl::vector<T>::operator []' : 2 overloads have similar conversions c:\program files (x86)\microsoft visual studio 8\vc\include\cl\cl.hpp 3484
Error 9 error C2228: left of '.second' must have class/struct/union c:\program files (x86)\microsoft visual studio 8\vc\include\cl\cl.hpp 3484


They refer to the C++ bindings header. I searched on the C++ bindings post, but I didn`t find anything. I use MS Visual Studio 2005 and my OS is Windows 7.

Thanks.