cwindowslinkeropencl

Linking OpenCL libraries in Windows 8 (MinGW)


I've searched high and low for an answer, so I apologize if this is something trivial that I haven't been able to sort on my own.

I just got new Alienware aurora with dual 780i gpus that I'm going to be using for CT image reconstruction. I'm planning to work in OpenCL because that's what I already know. Up to this point I've only worked on a Mac and compiling code with the OpenCL framework there is pretty trivial. Now, in Windows 8.1, things are a little less so.

I've installed the NVidia Cuda SDK which comes with all of the OpenCL headers as well as the libraries (all installed in the standard locations) and started out with trying to configure Code::blocks with MinGW to compile and link the OpenCL library. I always got the same error (scroll down to see it). I've linked libraries before so I'm 99% I've configured things correctly there, but obviously I missed something. To see what I did go to http://www.obellianne.fr/alexandre/tutorials/OpenCL/tuto_opencl_codeblocks.php.

I've since moved to the command line so that I can more fully configure things but alas, even with all of my careful configuring I keep getting the same errors.
The call that I've been using from the DOS prompt is the following:

gcc -v -Wall -std=c99 -I "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\include" -L "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\lib\x64" main.c -lOpenCL

and my output is this:

C:\Users\john\AppData\Local\Temp\ccGTa4TT.o:main.c:(.text+0x5f): undefined reference to `clGetPlatformIDs@12'
C:\Users\john\AppData\Local\Temp\ccGTa4TT.o:main.c:(.text+0xb5): undefined reference to `clGetDeviceIDs@24'
C:\Users\john\AppData\Local\Temp\ccGTa4TT.o:main.c:(.text+0xf3): undefined reference to `clGetDeviceIDs@24'
C:\Users\john\AppData\Local\Temp\ccGTa4TT.o:main.c:(.text+0x141): undefined reference to `clGetDeviceInfo@20'
C:\Users\john\AppData\Local\Temp\ccGTa4TT.o:main.c:(.text+0x18f): undefined reference to `clGetDeviceInfo@20'
C:\Users\john\AppData\Local\Temp\ccGTa4TT.o:main.c:(.text+0x1bf): undefined reference to `clGetDeviceInfo@20'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\john\AppData\Local\Temp\ccGTa4TT.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

(I've culled things down a little bit but can update with more detail if needed)

The strange thing is, after much fiddling, the linker is linking the library (well, not, but at least finding the library and attempting to link it).

I know that people run into these issues when -lOpenCL is in the wrong place so I've tried placing it just about anywhere I can think to with no success. It always throws the same errors.

The source code for my program can be found at the very bottom. It's cut and pasted from a book example and I've successfully compiled it on my mac.

Any thoughts?

Thanks, John

#include <stdio.h>
#include <stdlib.h>
#include <CL/cl.h>
int main()
{
   /* Host/device data structures */
   cl_platform_id platform;
   cl_device_id dev;
   cl_uint addr_data;
   cl_int err;

   /* Extension data */
   char name_data[48], ext_data[4096];

   /* Identify a platform */
   err = clGetPlatformIDs(1, &platform, NULL);
   if(err < 0) {
      perror("Couldn't find any platforms");
      exit(1);
   }

   /* Access a device, preferably a GPU */
   /* Changed on 2/12 to fix the CL_INVALID_VALUE error */
   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);
   }

   /* Access device name */
   err = clGetDeviceInfo(dev, CL_DEVICE_NAME,
      48 * sizeof(char), name_data, NULL);
   if(err < 0) {
      perror("Couldn't read extension data");
      exit(1);
   }

   /* Access device address size */
   clGetDeviceInfo(dev, CL_DEVICE_ADDRESS_BITS,
      sizeof(addr_data), &addr_data, NULL);

   /* Access device extensions */
   clGetDeviceInfo(dev, CL_DEVICE_EXTENSIONS,
      4096 * sizeof(char), ext_data, NULL);

   printf("NAME: %s\nADDRESS_WIDTH: %u\nEXTENSIONS: %s\n",
      name_data, addr_data, ext_data);

return 0;

}

Solution

  • Figured it out. Which is good, because I was about to have a nervous breakdown.

    With the version of mingw I have installed (via the installer tool) I have to link against the 32 bit libraries.

    GCC: Compiling an OpenCL host on Windows