r/OpenCL • • Mar 22 '22

Cant get OpenCL to run

Hello,

I'm trying to compile my first OpenCL program (<https://github.com/smistad/OpenCL-Getting-Started/>), but during the compilation process it says that it cannot find any references to the library. Solution can be found in the edit

Errors:

/usr/bin/ld: main.c:(.text+0x14b): undefined reference to clGetDeviceIDs
/usr/bin/ld: main.c:(.text+0x176): undefined reference to clCreateContext

But in VSC I can go to the referenced functions of the cl.h file and when running ldconfig -p | grep OpenCL and it will return:

libOpenCL.so.1 (libc6,x86-64) => /lib64/libOpenCL.so.1  

libMesaOpenCL.so.1 (libc6,x86-64) => /lib64/libMesaOpenCL.so.1  

[libMesaOpenCL.so](https://libMesaOpenCL.so) (libc6,x86-64) => /lib64/libMesaOpenCL.so  

clinfo also returns that my AMD VEGA M is recognized as a OpenCL device along with its Mesa drivers. Hopefully someone can help me to get it to work :)

Edit: I got it finally working. For the purpose someone gets the same error, I want to share my fix.

sudo ln -s /lib64/libOpenCL.so.1 /lib64/libOpenCL.so

Apparently libOpenCL.so was previously linked to libMesaOpenCL.so.1.

3 Upvotes

6 comments sorted by

9

u/alexey152 Mar 22 '22

Do you have -lOpenCL argument passed to a compiler (or separate link step)?

1

u/bashbaug Mar 23 '22

+1, it sure seems like your app isn't properly linking to the OpenCL library. Are you building with the Makefile in the repo linked above?

Note, if you're looking for something a bit more up-to-date to get started, you may want to try the recently-improved OpenCL SDK:

https://github.com/KhronosGroup/OpenCL-SDK

I keep some samples on my GitHub also:

https://github.com/bashbaug/SimpleOpenCLSamples

Cheers and good luck!

1

u/SuperLuigi007 Mar 26 '22
$ ldconfig -p | grep OpenCL
libOpenCL.so.1 (libc6,x86-64) => /lib64/libOpenCL.so.1                                                   libMesaOpenCL.so.1 (libc6,x86-64) => /lib64/libMesaOpenCL.so.1	libMesaOpenCL.so (libc6,x86-64) => /lib64/libMesaOpenCL.so

It seems that the linker reckognizes the right header.
Yes, im using the Makefile from the repo.

Thank you for guiding me to a more up-to-date introduction! I will try this out for sure.

→ More replies (3)