Reputation: 16968
Configuration question here, will hopefully help others in the future.
I created a folder, "C:\openCLcode\include\" which has all the necessary files from the Khronos site: http://www.khronos.org/registry/cl/
Now I want to create a Code::Blocks project that runs openCL. So I paste in some sample code and change the include paths:
In my .c file:
#include <C:\openCLcode\include\cl.h>
And within that cl.h
file it complained about cl_platform.h
so I fixed that path too:
#include <C:\openCLcode\include\cl_platform.h>
Now the problem I get is: undefined reference to 'clGetPlatformIDs@12'
Here is the offending function and line:
cl_device_id create_device() {
cl_platform_id platform;
cl_device_id dev;
int err;
/* Identify a platform */
//////////////THIS IS THE LINE WITH ERROR:////////////
err = clGetPlatformIDs(1, &platform, NULL);
//////////////////////////////////////////////////////
if(err < 0) {
perror("Couldn't identify a platform");
exit(1);
}
/* Access a device */
err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &dev, NULL);
if(err == CL_DEVICE_NOT_FOUND) {
err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 1, &dev, NULL);
}
if(err < 0) {
perror("Couldn't access any devices");
exit(1);
}
return dev;
}
I feel like I really screwed up my include scheme.... Could someone recommend a better way to go about this?
Much appreciated
Upvotes: 1
Views: 3557
Reputation: 343
You need to link libOpenCL.a library to your project.
1) Right click on you project(in codeblocks)
2) Select "Build options"
3) Select tab "Linker settings"
4) Press "Add" button
5) Select path with openCL libraries and choose libOpenCL.a.
Or you can compile OpenCL with you project:) Just add all openCL .cpp files in you project and try build it.
Upvotes: 6