c++cmacoslinker-errorspocl

why is linking to libOpenCL.dylib failing with undefined symbol


I am trying to build the pocl library on MacOS

System:

MBP 16" 2019
Intel i9, AMD Radeon 5500m
Mac OS 12.4
using bash, instead of zsh
llvm from home-brew, -version 14

I have the following in my .bash_profile to setup the build environment

export PATH=/usr/local/opt/llvm/bin:$PATH
export CC=clang
export CMAKE_C_COMPILER=clang
export CXX=clang++
export CMAKE_CXX_COMPILER=clang++

I go and clone the repo with git, cd into the source directory, mkdir build

Then in build/ run:

cmake .. -DENABLE_TESTS=OFF -DENABLE_EXAMPLES=OFF -DENABLE_ICD=OFF

The config seems to work and then when I run make everything builds, and gets to the end but then gives me the following error:

[100%] Linking C executable poclcc
clang-14: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]
Undefined symbols for architecture x86_64:
  "_clBuildProgram", referenced from:
      _main in poclcc.c.o
      _poclu_load_program_multidev in libpoclu.a(misc.c.o)
  "_clCreateCommandQueue", referenced from:
      _poclu_get_any_device2 in libpoclu.a(misc.c.o)
      _poclu_get_multiple_devices in libpoclu.a(misc.c.o)
  "_clCreateContext", referenced from:
      _main in poclcc.c.o
      _poclu_get_any_device2 in libpoclu.a(misc.c.o)
      _poclu_get_multiple_devices in libpoclu.a(misc.c.o)
  "_clCreateContextFromType", referenced from:
      _poclu_create_any_context in libpoclu.a(misc.c.o)
  "_clCreateProgramWithBinary", referenced from:
      _poclu_load_program_multidev in libpoclu.a(misc.c.o)
  "_clCreateProgramWithIL", referenced from:
      _poclu_load_program_multidev in libpoclu.a(misc.c.o)
  "_clCreateProgramWithSource", referenced from:
      _main in poclcc.c.o
      _poclu_load_program_multidev in libpoclu.a(misc.c.o)
  "_clGetDeviceIDs", referenced from:
      _main in poclcc.c.o
      _poclu_get_any_device2 in libpoclu.a(misc.c.o)
      _poclu_get_multiple_devices in libpoclu.a(misc.c.o)
  "_clGetDeviceInfo", referenced from:
      _main in poclcc.c.o
      _poclu_load_program_multidev in libpoclu.a(misc.c.o)
  "_clGetPlatformIDs", referenced from:
      _main in poclcc.c.o
      _poclu_create_any_context in libpoclu.a(misc.c.o)
      _poclu_get_any_device2 in libpoclu.a(misc.c.o)
      _poclu_get_multiple_devices in libpoclu.a(misc.c.o)
  "_clGetProgramBuildInfo", referenced from:
      _main in poclcc.c.o
      _poclu_show_program_build_log in libpoclu.a(misc.c.o)
  "_clGetProgramInfo", referenced from:
      _main in poclcc.c.o
      _poclu_show_program_build_log in libpoclu.a(misc.c.o)
  "_clReleaseContext", referenced from:
      _main in poclcc.c.o
  "_clReleaseProgram", referenced from:
      _main in poclcc.c.o
ld: symbol(s) not found for architecture x86_64

I checked and libOpenCL.dylib was successfully built in the pocl/build/lib/CL/ directory. Just as a check, I tried compiling clinfo with a direct link to this library and it gave me the same set of error messages shown above.

Running nm libOpenCL.dylib | grep clBuildProgram prints the following:

0000000000013850 t _clBuildProgram

So its in there, but it is a local text section symbol. I don't actually know what that means though, and if that means it should work, or should not work. I don't actually understand what the problem is here or why this linking is failing, or what to do about it. Looking for some guidance on that.


Solution

  • The meaning of the lower case t is that the symbols are local, i.e. not externally visible to linking programs. Upper case T would be externally visible.

    POCL has a number of configuration options, not all of which are documented in the Build section of the docs. The VISIBILITY_HIDDEN option is on by default unless the ENABLE_PROXY option is on.

    In build/, running:

    cmake .. -DENABLE_ICD=OFF -DVISIBILITY_HIDDEN=OFF

    and then:

    make

    the compile succeeds to the end. Then in build/lib/CL/ running:

    nm libOpenCL.dylib | grep clBuildProgram

    now prints:

    0000000000013790 T _clBuildProgram