Linux ubuntu + opencl + qtcreator -> missing lib

I’m trying my own addon ofxMSAOpenCL :slight_smile: on linux, according to pull requests it should be working on Linux.

I’ve installed CUDA and opencl-headers, and clinfo is returning OK CL info, but I’m getting link errors in QT Creator (can’t find any clXXX functions).

I’ve tried adding ‘-lOpenCL’ ‘lOpenCL’ ‘OpenCL’ (and all lowercase) to of.linkerflags in the qbs and I always get ‘cannot find’ or ‘file not found’. Likewise when i add opencl or OpenCL to the addon_config.mk.

Is this just a symlink issue? Do I need to place a libOpenCL.so somewhere in my libpath?

worth noting that the cuda lib (/usr/local/cuda-8.0/targets/x86_64-linux/lib/libOpenCL.so.1.0.0) is only 25KB, is that normal?

$ gcc -lOpenCL
/usr/bin/ld: cannot find -lOpenCL
collect2: error: ld returned 1 exit status

$ whereis libOpenCL
libOpenCL: /usr/share/man/man7/libOpenCL.7.gz

$ ldconfig -p | grep libOpenCL
libOpenCL.so.1 (libc6,x86-64) => /usr/local/cuda-8.0/targets/x86_64-linux/lib/libOpenCL.so.1
libOpenCL.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libOpenCL.so.1
libOpenCL.so (libc6,x86-64) => /usr/local/cuda-8.0/targets/x86_64-linux/lib/libOpenCL.so

$ sudo find / -iname "libopencl*" -ls
  3290072      0 lrwxrwxrwx   1 root     root           18 Jan 26  2017 /usr/local/cuda-8.0/targets/x86_64-linux/lib/libOpenCL.so.1.0 -> libOpenCL.so.1.0.0
  3290070      0 lrwxrwxrwx   1 root     root           14 Jan 26  2017 /usr/local/cuda-8.0/targets/x86_64-linux/lib/libOpenCL.so -> libOpenCL.so.1
  3290067     28 -rw-r--r--   1 root     root        25840 Jan 26  2017 /usr/local/cuda-8.0/targets/x86_64-linux/lib/libOpenCL.so.1.0.0
  3290071      0 lrwxrwxrwx   1 root     root           16 Jan 26  2017 /usr/local/cuda-8.0/targets/x86_64-linux/lib/libOpenCL.so.1 -> libOpenCL.so.1.0
  3278941     44 -rw-r--r--   1 root     root        43456 Dec 18  2015 /usr/lib/x86_64-linux-gnu/libOpenCL.so.1.0.0
  3278942      0 lrwxrwxrwx   1 root     root           18 Dec 18  2015 /usr/lib/x86_64-linux-gnu/libOpenCL.so.1 -> libOpenCL.so.1.0.0
  4987899      0 lrwxrwxrwx   1 root     root           14 Dec 18  2015 /usr/share/man/man7/libOpenCL.so.7.gz -> libOpenCL.7.gz
  4987898      4 -rw-r--r--   1 root     root         2090 Dec 18  2015 /usr/share/man/man7/libOpenCL.7.gz
  7734948     24 -rw-r--r--   1 root     root        21855 Dec 18  2015 /usr/share/doc/ocl-icd-libopencl1/html/libOpenCL.html

$ clinfo
clinfo: /usr/local/cuda/lib64/libOpenCL.so.1: no version information available (required by clinfo)
Number of platforms                               1
  Platform Name                                   NVIDIA CUDA
  Platform Vendor                                 NVIDIA Corporation
  Platform Version                                OpenCL 1.2 CUDA 9.0.194
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_fp64 cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_copy_opts cl_nv_create_buffer
  Platform Extensions function suffix             NV

  Platform Name                                   NVIDIA CUDA
Number of devices                                 1
  Device Name                                     GeForce GTX 1070 with Max-Q Design
  Device Vendor                                   NVIDIA Corporation
  Device Vendor ID                                0x10de
  Device Version                                  OpenCL 1.2 CUDA
  Driver Version                                  384.90
  Device OpenCL C Version                         OpenCL C 1.2 
  Device Type                                     GPU
  Device Profile                                  FULL_PROFILE
  Device Topology (NV)                            PCI-E, 01:00.0
  Max compute units                               16
  Max clock frequency                             1265MHz
  Compute Capability (NV)                         6.1
  Device Partition                                (core)
    Max number of sub-devices                     1
    Supported partition types                     None
  Max work item dimensions                        3
  Max work item sizes                             1024x1024x64
  Max work group size                             1024
  Preferred work group size multiple              32
  Warp size (NV)                                  32
  Preferred / native vector sizes                 
    char                                                 1 / 1       
    short                                                1 / 1       
    int                                                  1 / 1       
    long                                                 1 / 1       
    half                                                 0 / 0        (n/a)
    float                                                1 / 1       
    double                                               1 / 1        (cl_khr_fp64)
  Half-precision Floating-point support           (n/a)
  Single-precision Floating-point support         (core)
    Denormals                                     Yes
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 Yes
    Round to infinity                             Yes
    IEEE754-2008 fused multiply-add               Yes
    Support is emulated in software               No
    Correctly-rounded divide and sqrt operations  Yes
  Double-precision Floating-point support         (cl_khr_fp64)
    Denormals                                     Yes
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 Yes
    Round to infinity                             Yes
    IEEE754-2008 fused multiply-add               Yes
    Support is emulated in software               No
    Correctly-rounded divide and sqrt operations  No
  Address bits                                    64, Little-Endian
  Global memory size                              8508145664 (7.924GiB)
  Error Correction support                        No
  Max memory allocation                           2127036416 (1.981GiB)
  Unified memory for Host and Device              No
  Integrated memory (NV)                          No
  Minimum alignment for any data type             128 bytes
  Alignment of base address                       4096 bits (512 bytes)
  Global Memory cache type                        Read/Write
  Global Memory cache size                        262144
  Global Memory cache line                        128 bytes
  Image support                                   Yes
    Max number of samplers per kernel             32
    Max size for 1D images from buffer            134217728 pixels
    Max 1D or 2D image array size                 2048 images
    Max 2D image size                             16384x32768 pixels
    Max 3D image size                             16384x16384x16384 pixels
    Max number of read image args                 256
    Max number of write image args                16
  Local memory type                               Local
  Local memory size                               49152 (48KiB)
  Registers per block (NV)                        65536
  Max constant buffer size                        65536 (64KiB)
  Max number of constant args                     9
  Max size of kernel argument                     4352 (4.25KiB)
  Queue properties                                
    Out-of-order execution                        Yes
    Profiling                                     Yes
  Prefer user sync for interop                    No
  Profiling timer resolution                      1000ns
  Execution capabilities                          
    Run OpenCL kernels                            Yes
    Run native kernels                            No
    Kernel execution timeout (NV)                 Yes
  Concurrent copy and kernel execution (NV)       Yes
    Number of async copy engines                  2
  printf() buffer size                            1048576 (1024KiB)
  Built-in kernels                                
  Device Available                                Yes
  Compiler Available                              Yes
  Linker Available                                Yes
  Device Extensions                               cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_fp64 cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_copy_opts cl_nv_create_buffer

NULL platform behavior
  clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...)  No platform
  clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...)   No platform
  clCreateContext(NULL, ...) [default]            No platform
  clCreateContext(NULL, ...) [other]              Success [NV]
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU)  No platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU)  No platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR)  No platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM)  No platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL)  No platform

UPDATE

I tried

$ sudo ln -s /usr/local/cuda/targets/x86_64-linux/lib/libOpenCL.so /usr/local/lib/libOpenCL.so
$ sudo ldconfig
$ whereis libOpenCL
libOpenCL: /usr/local/lib/libOpenCL.so /usr/share/man/man7/libOpenCL.7.gz
$ gcc -lOpenCL
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

So that looks like a step in the right direction, at least gcc can find libOpenCL now but:

  1. Do I really have to manually symlink the lib?
  2. QT Creator still says ‘:-1: error: error: OpenCL: No such file or directory’

All I did was adding OpenCL to pkgconfig. I never used OpenCL on ubuntu. how did you install it? Is it included in the repositories? Does pkg-config --libs OpenCL work? I suspect that your system is not correctly configured to find all the paths to your OpenCL installation.

hmm… as @memo did, I made symbolic link and compiled successfully. but runtime error occured…

environment:
arch linux (manjaro)
oF 0.10.0

[verbose] 

*********
OpenCL Device information for device #0
 cl_device_id................0x55b3d1669270
 vendorName..................Intel(R) Corporation
 deviceName..................Intel(R) HD Graphics
 driverVersion...............r5.0.63503
 deviceVersion...............OpenCL 2.0 
 maxComputeUnits.............23
 maxWorkItemDimensions.......3
 maxWorkItemSizes[0].........256
 maxWorkGroupSize............256
 maxClockFrequency...........1050
 maxMemAllocSize.............4095.992 MB
 imageSupport................YES
 maxReadImageArgs............128
 maxWriteImageArgs...........128
 image2dMaxWidth.............16384
 image2dMaxHeight............16384
 image3dMaxWidth.............16384
 image3dMaxHeight............16384
 image3dMaxDepth.............2048
 maxSamplers.................16
 maxParameterSize............1024
 globalMemCacheSize..........0.500 MB
 globalMemSize...............12638.537 MB
 maxConstantBufferSize.......4194296.000 KB
 maxConstantArgs.............8
 localMemSize................64.000 KB
 errorCorrectionSupport......NO
 profilingTimerResolution....83
 endianLittle................1
 profile.....................FULL_PROFILE
 extensions..................cl_intel_accelerator cl_intel_advanced_motion_estimation cl_intel_device_side_avc_motion_estimation cl_intel_driver_diagnostics cl_intel_media_block_io cl_intel_motion_estimation cl_intel_planar_yuv cl_intel_packed_yuv cl_intel_required_subgroup_size cl_intel_subgroups cl_intel_subgroups_short cl_intel_va_api_media_sharing cl_khr_3d_image_writes cl_khr_byte_addressable_store cl_khr_depth_images cl_khr_fp16 cl_khr_fp64 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_icd cl_khr_image2d_from_buffer cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_mipmap_image cl_khr_mipmap_image_writes cl_khr_spir cl_khr_subgroups 
*********


[notice ] Using OpenCL Platform: 0x0x7efd90658ae0
[notice ] Using OpenCL Device: 0x0x7efd9065a6c0
[notice ] Created OpenCL context: SUCCESS
[verbose] OpenCLBuffer::initBuffer
[verbose] OpenCLMemoryObject::memoryObjectInit
[verbose] OpenCLBuffer::initFromGLObject
[verbose] OpenCLMemoryObject::memoryObjectInit
error: Not implemented
[verbose] OpenCLMemoryObject::~OpenCLMemoryObject
[verbose] OpenCLMemoryObject::~OpenCLMemoryObject
[verbose] OpenCL::~OpenCL
make: *** [/home/icq4ever/oF/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk:190: run] Error 255

this example was run well on windows 10 with CUDA 9.2