clMathLibraries / clBLAS

a software library containing BLAS functions written in OpenCL
Apache License 2.0
843 stars 237 forks source link

undefined reference OpenCL function error #326

Closed ysh329 closed 6 years ago

ysh329 commented 6 years ago

I tried to gcc gemm example in readme but failed.

$ gcc ./gemm.c -I/usr/local/include -I/opt/AMDAPPSDK-3.0/include
./gemm.c: In function ‘main’:
./gemm.c:64:5: warning: ‘clCreateCommandQueue’ is deprecated [-Wdeprecated-declarations]
     queue = clCreateCommandQueue( ctx, device, 0, &err );
     ^
In file included from /usr/local/include/clBLAS.h:35:0,
                 from ./gemm.c:5:
/opt/AMDAPPSDK-3.0/include/CL/cl.h:1359:1: note: declared here
 clCreateCommandQueue(cl_context                     /* context */,
 ^
/tmp/cc9uBwlj.o: In function `main':
gemm.c:(.text+0x70): undefined reference to `clGetPlatformIDs'
gemm.c:(.text+0x96): undefined reference to `clGetDeviceIDs'
gemm.c:(.text+0xc8): undefined reference to `clCreateContext'
gemm.c:(.text+0xe8): undefined reference to `clCreateCommandQueue'
gemm.c:(.text+0xf1): undefined reference to `clblasSetup'
gemm.c:(.text+0x116): undefined reference to `clCreateBuffer'
gemm.c:(.text+0x13c): undefined reference to `clCreateBuffer'
gemm.c:(.text+0x162): undefined reference to `clCreateBuffer'
gemm.c:(.text+0x196): undefined reference to `clEnqueueWriteBuffer'
gemm.c:(.text+0x1cd): undefined reference to `clEnqueueWriteBuffer'
gemm.c:(.text+0x204): undefined reference to `clEnqueueWriteBuffer'
gemm.c:(.text+0x27a): undefined reference to `clblasSgemm'
gemm.c:(.text+0x292): undefined reference to `clWaitForEvents'
gemm.c:(.text+0x2c5): undefined reference to `clEnqueueReadBuffer'
gemm.c:(.text+0x2d8): undefined reference to `clReleaseMemObject'
gemm.c:(.text+0x2e4): undefined reference to `clReleaseMemObject'
gemm.c:(.text+0x2f0): undefined reference to `clReleaseMemObject'
gemm.c:(.text+0x2f5): undefined reference to `clblasTeardown'
gemm.c:(.text+0x301): undefined reference to `clReleaseCommandQueue'
gemm.c:(.text+0x30d): undefined reference to `clReleaseContext'
collect2: error: ld returned 1 exit status
CNugteren commented 6 years ago

You should link against OpenCL, e.g. add -lopencl

ysh329 commented 6 years ago

fixed. Thanks my big brother! 😘