提问人:Vince W. 提问时间:7/8/2022 更新时间:7/8/2022 访问量:180
为什么链接到 libOpenCL.dylib 失败并显示未定义的符号
why is linking to libOpenCL.dylib failing with undefined symbol
问:
我正在尝试在 MacOS 上构建 pocl 库
系统:
MBP 16" 2019
Intel i9, AMD Radeon 5500m
Mac OS 12.4
using bash, instead of zsh
llvm from home-brew, -version 14
我在.bash_profile中设置了以下内容来设置构建环境
export PATH=/usr/local/opt/llvm/bin:$PATH
export CC=clang
export CMAKE_C_COMPILER=clang
export CXX=clang++
export CMAKE_CXX_COMPILER=clang++
我去用 git 克隆 repo,cd 到源目录,mkdir build
然后在运行中:build/
cmake .. -DENABLE_TESTS=OFF -DENABLE_EXAMPLES=OFF -DENABLE_ICD=OFF
配置似乎有效,然后当我运行 make everything 构建并到达最后,但随后给我以下错误:
[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
我检查并成功在目录中构建了 libOpenCL.dylib。作为检查,我尝试使用指向该库的直接链接进行编译,它给了我与上面所示相同的一组错误消息。pocl/build/lib/CL/
clinfo
运行将打印以下内容:nm libOpenCL.dylib | grep clBuildProgram
0000000000013850 t _clBuildProgram
所以它在那里,但它是一个本地文本部分符号。我实际上不知道这意味着什么,以及这是否意味着它应该起作用,或者不应该起作用。我实际上不明白这里的问题是什么,或者为什么这个链接会失败,或者该怎么做。寻找一些指导。
答:
小写字母 t 的含义是符号是局部的,即链接程序在外部不可见。大写字母 T 在外部可见。
POCL 有许多配置选项,但并非所有选项都记录在文档的“构建”部分中。默认情况下,该选项处于打开状态,除非该选项处于打开状态。VISIBILITY_HIDDEN
ENABLE_PROXY
在 中,运行:build/
cmake .. -DENABLE_ICD=OFF -DVISIBILITY_HIDDEN=OFF
然后:
make
编译成功到最后。然后在运行中:build/lib/CL/
nm libOpenCL.dylib | grep clBuildProgram
现在打印:
0000000000013790 T _clBuildProgram
评论