Command line compilation

I’m trying to compile an OpenCL program on windows via command line using GCC but I can’t get it to work.

g++ -c -I "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\include" src/conv_ocl.cpp

g++ -L "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\lib\Win32" -lOpenCL -o conv_ocl conv_ocl.o

The first line works fine and the compiler doesn’t complain. The second line throws undefined reference errors:

conv_ocl.o:conv_ocl.cpp:(.text+0x1b5): undefined reference to `clGetPlatformIDs@12'

conv_ocl.o:conv_ocl.cpp:(.text+0x1ec): undefined reference to `clGetDeviceIDs@24'

conv_ocl.o:conv_ocl.cpp:(.text+0x224): undefined reference to `clCreateContext@24'

conv_ocl.o:conv_ocl.cpp:(.text+0x253): undefined reference to `clCreateCommandQueue@20'

conv_ocl.o:conv_ocl.cpp:(.text+0x28a): undefined reference to `clCreateBuffer@24'

conv_ocl.o:conv_ocl.cpp:(.text+0x2c5): undefined reference to `clCreateBuffer@24'

conv_ocl.o:conv_ocl.cpp:(.text+0x2ff): undefined reference to `clCreateBuffer@24'

conv_ocl.o:conv_ocl.cpp:(.text+0x354): undefined reference to `clEnqueueWriteBuffer@36'

conv_ocl.o:conv_ocl.cpp:(.text+0x382): undefined reference to `clCreateProgramWithSource@20'

conv_ocl.o:conv_ocl.cpp:(.text+0x3ba): undefined reference to `clBuildProgram@24'

conv_ocl.o:conv_ocl.cpp:(.text+0x3ff): undefined reference to `clGetProgramBuildInfo@24'

conv_ocl.o:conv_ocl.cpp:(.text+0x44a): undefined reference to `clGetProgramBuildInfo@24'

conv_ocl.o:conv_ocl.cpp:(.text+0x4a4): undefined reference to `clCreateKernel@12'

conv_ocl.o:conv_ocl.cpp:(.text+0x4c4): undefined reference to `clCreateKernel@12'

conv_ocl.o:conv_ocl.cpp:(.text+0x4ef): undefined reference to `clSetKernelArg@16'

conv_ocl.o:conv_ocl.cpp:(.text+0x51a): undefined reference to `clSetKernelArg@16'

conv_ocl.o:conv_ocl.cpp:(.text+0x542): undefined reference to `clSetKernelArg@16'

conv_ocl.o:conv_ocl.cpp:(.text+0x56a): undefined reference to `clSetKernelArg@16'

conv_ocl.o:conv_ocl.cpp:(.text+0x592): undefined reference to `clSetKernelArg@16'

conv_ocl.o:conv_ocl.cpp:(.text+0x5bd): more undefined references to `clSetKernelArg@16' follow

conv_ocl.o:conv_ocl.cpp:(.text+0x6c6): undefined reference to `clEnqueueNDRangeKernel@36'

conv_ocl.o:conv_ocl.cpp:(.text+0x718): undefined reference to `clEnqueueNDRangeKernel@36'

conv_ocl.o:conv_ocl.cpp:(.text+0x76a): undefined reference to `clEnqueueReadBuffer@36'

conv_ocl.o:conv_ocl.cpp:(.text+0x7b7): undefined reference to `clFlush@4'

conv_ocl.o:conv_ocl.cpp:(.text+0x7c5): undefined reference to `clFinish@4'

conv_ocl.o:conv_ocl.cpp:(.text+0x7d3): undefined reference to `clReleaseKernel@4'

conv_ocl.o:conv_ocl.cpp:(.text+0x7e1): undefined reference to `clReleaseKernel@4'

conv_ocl.o:conv_ocl.cpp:(.text+0x7ef): undefined reference to `clReleaseProgram@4'

conv_ocl.o:conv_ocl.cpp:(.text+0x800): undefined reference to `clReleaseMemObject@4'

conv_ocl.o:conv_ocl.cpp:(.text+0x811): undefined reference to `clReleaseMemObject@4'

conv_ocl.o:conv_ocl.cpp:(.text+0x822): undefined reference to `clReleaseMemObject@4'

conv_ocl.o:conv_ocl.cpp:(.text+0x830): undefined reference to `clReleaseCommandQueue@4'

conv_ocl.o:conv_ocl.cpp:(.text+0x83e): undefined reference to `clReleaseContext@4'

collect2: ld returned 1 exit status

It kind of looks like the linking isn’t working correctly, can anyone spot any obvious mistakes in the compiler invocations?

Regards,

This looks like a header file problem. It is trying to find those functions in the header file but does not recognize them. Try opening the CL.h file and checking the name of the functions and change them accordingly.

If you haven’t i think you still need to include the CL.h file in your code even when you do -lOpenCL.