[SOLVED] How to compile OpenCL program?
FedoraForum.org - Fedora Support Forums and Community
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2011
    Location
    Moscow, Russia
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to compile OpenCL program?

    Hi, Gurus.

    I tried to compile OpenCL program. Very easy.

    #include <stdio.h>
    #include <CL/cl.h>
    main() {
    cl_int errNum;
    cl_uint numPlatforms;
    cl_platform_id * platformIds;
    cl_context context = NULL;

    errNum = clGetPlatformIDs(0, NULL, &numPlatforms);
    platformIds = (cl_platform_id *)alloca(
    sizeof(cl_platform_id) * numPlatforms);
    errNum = clGetPlatformIDs(numPlatforms, platformIds, NULL);
    printf("Hello\n");
    }

    I installed OpenCL SDK from AMD. Examples (binary) work OK.
    now I try to compile this test program and it has:

    [alexei@localhost openCl]$ gcc -c -I/opt/AMDAPP/include OpenClEx1.c
    [alexei@localhost openCl]$ gcc -o OpenClEx1 OpenClEx1.o
    OpenClEx1.o: In function `main':
    OpenClEx1.c.text+0x22): undefined reference to `clGetPlatformIDs'
    OpenClEx1.c.text+0x7f): undefined reference to `clGetPlatformIDs'
    collect2: ld returned 1 exit status
    [alexei@localhost openCl]$

    Does any one know what to do next?

  2. #2
    Join Date
    Jul 2011
    Location
    Birmingham, UK
    Age
    36
    Posts
    2,761
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to compile OpenCL program?

    You need to link your program with a library providing the OpenCL functions that you call.

    I've no experience with compiling OpenCL with GCC, only using the nvidia drivers hardware OpenCL, so I don't know what the library is called. At a guess, you need to add "-lopencl" or similar to the command line, but the SDK documentation should surely mention the right name.

    Otherwise, look to see what files with names matching "lib*.so*" or "lib*.a" were installed with the SDK, drop the ".*" and replace "lib" with "-l", and add that to the compiler command line. Running "ldd" on the binary examples may also show what library they're using. If the libraries are installed outside of /lib, /usr/lib or /usr/local/lib, e.g. "/opt/AMDAPP/lib", then before the "-l" option you also need "-L/AMD/lib/dir/location".

    Gareth

  3. #3
    Join Date
    Feb 2011
    Location
    Moscow, Russia
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to compile OpenCL program?

    Thanks, Gareth.

    Now it works.

    Thanks again 8)

    ---------- Post added at 07:44 PM ---------- Previous post was at 07:41 PM ----------

    Just for info:
    I use F15. x86_64, installed AMD OpenCL SDK into /opt/AMDAPP
    my Makefile:
    OpenClEx1 : OpenClEx1.o
    gcc -L/opt/AMDAPP/lib/x86_64/ -lOpenCL -o OpenClEx1 OpenClEx1.o
    OpenClEx1.o: OpenClEx1.c
    gcc -c -I/opt/AMDAPP/include OpenClEx1.c

  4. #4
    Join Date
    Mar 2009
    Location
    Northern California
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to compile OpenCL program?

    Hi

    I am feeling dumb.
    I have everything installed I can see :
    Installed Packages
    opencl-filesystem.noarch
    opencl-headers.noarch
    opencl-utils.x86_64
    opencl-utils-devel.x86_64

    Do I need to install other things?
    gcc -o file file.c-lopencl cannot find the opencl library

Similar Threads

  1. not able to compile the c program
    By simhakln123 in forum Using Fedora
    Replies: 1
    Last Post: 9th December 2010, 12:36 PM
  2. not able to compile the c program
    By simhakln123 in forum Using Fedora
    Replies: 1
    Last Post: 9th December 2010, 08:31 AM
  3. Compile 32-bit Program on a 64-bit OS
    By cc7gir in forum Using Fedora
    Replies: 4
    Last Post: 20th January 2010, 01:13 AM
  4. help me compile the program dvdbackup
    By d_GeNeRiT in forum Using Fedora
    Replies: 6
    Last Post: 14th April 2006, 11:06 AM
  5. Compile program issue
    By GreyWizzard in forum Using Fedora
    Replies: 5
    Last Post: 14th April 2006, 12:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •