Compiling a simple program

Hey guys,

this may be a simple question but I tried to get this code running for hours now without any feeling of success, so please help me!

I’m trying to compile a simple OpenCl program as follows:

[codebox]// standard utilities and systems includes

#include <oclUtils.h>

#include <cl_platform.h>

#include <stdio.h>

// defines, project


#define MEMSIZE_START (1<<10) //1KB

#define MEMSIZE_INCREMENT (1<<18) //256KB

#define MEMSIZE_END (1<<25) //32MB

#define CACHE_CLEAR_SIZE (1 << 24) //16 M

#define startDevice 0

#define endDevice 1

//enums, project



enum printMode { USER_READABLE, CSV };

enum memoryMode { PAGEABLE, PINNED };

enum accessMode { MAPPED, DIRECT };

// CL objects

cl_context cxGPUContext;

cl_command_queue cqCommandQueue;

cl_device_id *devices;

int main (void)


    // Get OpenCL platform ID for NVIDIA if available, otherwise default

cl_platform_id clSelectedPlatformID = NULL; 

cl_int ciErrNum = oclGetPlatformID (&clSelectedPlatformID);

//shrCheckError(ciErrNum, CL_SUCCESS);

// Find out how many devices there are

cl_uint ciDeviceCount;

//ciErrNum = clGetDeviceIDs (0, CL_DEVICE_TYPE_GPU, 0, NULL, &ciDeviceCount);

// Get and log the device info

devices = (cl_device_id*) malloc(sizeof(cl_device_id) * ciDeviceCount);

printf("HELLO OPENCL\n");

return 0;

} [/codebox]

with the g++ comand:

[font=“Courier New”]g++ -I ~/NVIDIA_GPU_Computing_SDK/OpenCL/common/inc/ -I ~/NVIDIA_GPU_Computing_SDK/shared/inc/ -L ~/NVIDIA_GPU_Computing_SDK/OpenCL/common/lib/liboclUtil.a -I ~/NVIDIA_GPU_Computing_SDK/OpenCL/common/inc/CL test.cpp -o TEST[/font]

and I always get the error:

[font=“Courier New”]/tmp/cckXzvA0.o: In function `main’:

test.cpp:(.text+0x15): undefined reference to `oclGetPlatformID’

collect2: ld returned 1 exit status[/font]

Does anybody know what I’ve done wrong?


running OpenSuse 11.1 x64 - g++ 4.3.2

I’m on Windows, but I’m guessing that the basics are the same. You are specifying OpenCL include path twice to g++ but never link to the OpenCL library. There should be a -L ~/NVIDIA_GPU_Computing_SDK/OpenCL/common/lib/OpenCL or similar somewhere in there.

Thanks for your quick reply Mr Nilsson,

I checked your specified path, there are two empty folders, [font=“Courier New”]Linux32[/font] and [font=“Courier New”]Linux64[/font], and one file, [font=“Courier New”]liboclUtil.a[/font], which I already linked to my g++ !
I guess above mentioned library is the OpenCl library?

It sounds like there is something wrong with your OpenCL installation, as it definitely should be a OpenCL library in at least one of the empty folders. Any Linux proficient users around here that can help us out?

OclUtils.h is a header file which is included with the Nvidia GPU computing SDK which has the reference to the function “oclGetPlatformID”. This has a OclUtils.cpp file too with the corresponding libraries. I have it on my windows system here under OpenCL\common\lib - OclUtils32.lib. I think a similar .a file should be present with the linux version too. That is the library and cpp you are missing. Check to see if you can find the above header and cpp file.