cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

jatin_gaur
Journeyman III

OpenCL Library link with GCC issue

Hi,

​I needed some help with linking the OpenCL libraries along with gcc.

​Thanks,

​Jatin

!

0 Likes
5 Replies
dipak
Big Boss

Hi Jatin,

Could you please share more details about the issue or kind of help you needed?

P.S. You've been whitelisted now.

Regards,

0 Likes
ernst0
Adept I

I feel dumb.  I assume I am to gcc -o filename  filename.c -lopencl

It is finding the includes okay but is that the link library I am supposed to add to the command like?

0 Likes

In general, the gcc command is:

gcc -o Template Template.c -I<OPENCL_HEADER_PATH> -lOpenCL -L<OPENCL_LIB_PATH>

One of the easiest ways to build using command line is add the path of the headers and library to the "PATH" environmental variable and avoid writing -I and -L option each time.

Also, one can set corresponding environmental variables and use them as shown below:
gcc -o Template Template.c -I$OPENCL_HEADER -lOpenCL -L$OPENCL_LIB

If header and library files are placed under the same root directory, then one environmental variable can serve the purpose. For example, assuming "include" and "lib" are two sub-folders that contain the headers and libraries respectively, then the command can be:
gcc -o Template Template.c -I$OPENCL_ROOT/include -lOpenCL -L$OPENCL_ROOT/lib

P.S. Depending on the OS, driver and OpenCL SDK package, the path of the header and library can vary. So, please check the related documents to locate the files on your system.

Thanks.

Thank You.

I am learning OpenCL and there are nuances.

I'm spoiled. Mostly installing packages do all the work.

0 Likes

Yes, installation packages mostly set these environmental variables. As a programmer, you just need to use them to build an OpenCL program. However, the exact names can vary depending on the package. So, please make sure that you are using the appropriate libraries and headers particularly when you have multiple OpenCL SDK packages installed at the same time.

Thanks

0 Likes