Errors Running AMD OpenCL Tutorial Code

Hi folks

It’s been many years since I did any C++ coding. I’ve recently begun some work at grad school that requires me to learn openCL. I’ve installed the newest SDK, and I’m trying to run one of the example codes given in the ATi Parallel Processing Programming Guide (http://developer.amd.com/gpu_assets/ATI … _Guide.pdf) at Section 1.9.1. I ran the code using

gcc -I../include/ eg1.cpp

and I got the following error message.


/tmp/ccfkQlRl.o: In function `main':
eg1.cpp:(.text+0x25): undefined reference to `clGetPlatformIDs'
eg1.cpp:(.text+0x48): undefined reference to `clGetDeviceIDs'
eg1.cpp:(.text+0x6f): undefined reference to `clCreateContext'
eg1.cpp:(.text+0x90): undefined reference to `clCreateCommandQueue'
eg1.cpp:(.text+0xb5): undefined reference to `clCreateProgramWithSource'
eg1.cpp:(.text+0xdf): undefined reference to `clBuildProgram'
eg1.cpp:(.text+0xf5): undefined reference to `clCreateKernel'
eg1.cpp:(.text+0x11a): undefined reference to `clCreateBuffer'
eg1.cpp:(.text+0x143): undefined reference to `clSetKernelArg'
eg1.cpp:(.text+0x186): undefined reference to `clEnqueueNDRangeKernel'
eg1.cpp:(.text+0x192): undefined reference to `clFinish'
eg1.cpp:(.text+0x1dd): undefined reference to `clEnqueueMapBuffer'
/tmp/ccfkQlRl.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

And I haven’t been able to figure out what I’m doing wrong. I would really appreciate any help.

Thanks

You need to link against the OpenCL library. Surely the examples from the ATI SDK come with makefiles or similar. Why not use them?

You can try

gcc -I../include/ eg1.cpp -lOpenCL

and see if it works (it should work if OpenCL is installed in the usual location).

Thanks, it works now!