Reputation: 27
I downloaded OpenCL from here : https://software.intel.com/en-us/intel-opencl/download. I tried AMD for OpenCL first, but all the pages I tried have said "404 page not found".
This is the code I am testing OpenCL with.
#include <stdlib.h>
#include <stdio.h>
#include <CL/cl.h>
int main() {
cl_device_id device_id;
cl_uint num_devices;
cl_int id = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 1, &device_id, &num_devices);
return 0;
}
I tried compiling this code with.
gcc opencl.c -I C:\Intel\OpenCL\sdk\include -L C:\Intel\OpenCL\sdk\lib\x64 -o opencl.exe
But I get this error.
undefined reference to `clGetDeviceIDs@24'
If I remove the line with the clGetDeviceIDs function it compiles fine.
I've also tried compiling with,
gcc opencl.c -I C:\Intel\OpenCL\sdk\include -lOpenCL -o opencl.exe
but it says...
cannot find -lOpenCL
I read somewhere that -lOpenCL is made when you download the OpenCL drivers. So I tried downloading the driver here : https://support.amd.com/en-us/kb-articles/Pages/OpenCL2-Driver.aspx. I installed the driver and then ran the setup but it said it doesn't detect any AMD graphics hardware.
I changed -L C:\Intel\OpenCL\sdk\lib\x64
to -L C:\Intel\OpenCL\sdk\lib\x86
and compiled with
gcc opencl.c -I C:\Intel\OpenCL\sdk\include -L C:\Intel\OpenCL\sdk\lib\x86 -lOpenCL -o opencl.exe
and it worked? So I check my system settings to make sure I have Windows 64 bit and it says
64-bit operating system, x64-based processor
. So did I install the wrong version of OpenCL?
Upvotes: 1
Views: 1806
Reputation: 20386
The choice of whether to use the 32-bit binary (x86) or the 64-bit binary (x64) is based on the target architecture of your application, not the architecture of the computer compiling the program. The reason the x86 version of the library worked and the x64 version didn't is that your compiler is compiling in 32-bit mode. Switch to compiling in x64 to get the x64 library to link properly.
I'm not incredibly familiar with gcc, so I don't know what flags control that behavior. Check your compiler documentation. Note that whether the compiler itself is 32-bit or 64-bit should be irrelevant.
Upvotes: 1