Results 1 to 6 of 6

Thread: Hello world program - compilation error

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    2

    Hello world program - compilation error

    Hello,

    I am new to OpenCL and I've been trying to compile the following piece of code, but with no success
    Code :
    #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:
    Code :
    /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

  2. #2

    Re: Hello world program - compilation error

    Try changing the order of your includes:
    Code :
    #include <CL/cl.hpp>
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    to

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

    Also you need to define "cl_int err"

  3. #3
    Junior Member
    Join Date
    Jan 2010
    Posts
    2

    Re: Hello world program - compilation error

    Reordering the #include statements fixed the problem. Thank you very much

  4. #4
    Junior Member
    Join Date
    Jan 2010
    Posts
    1

    Re: Hello world program - compilation error

    I'm new to opencl too, what is the command line to compile that piece of code please ?

  5. #5
    Junior Member
    Join Date
    Dec 2009
    Posts
    22

    Re: Hello world program - compilation error

    g++ yourfile.cpp -L/yourlib -I/yourinc -lOpenCL

  6. #6
    Junior Member
    Join Date
    Feb 2010
    Posts
    2

    Re: Hello world program - compilation error

    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>:perator []' : 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>:perator []' : 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>:perator []' : 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>:perator []' : 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.

Similar Threads

  1. program error
    By jai in forum OpenCL
    Replies: 4
    Last Post: 10-05-2012, 04:00 AM
  2. compilation error in VS2008,HELP!
    By fuxianjun in forum OpenCL
    Replies: 3
    Last Post: 05-18-2010, 07:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •