使用Bazel编译go-webp时libwebp出现arm64符号缺失问题排查咨询
编译go-webp时链接libwebp缺失SharpYuv符号的问题调试方案
问题背景
尝试用Bazel编译go-webp包,需从源码编译libwebp依赖,但在arm64架构的macOS上构建时,链接器提示缺失_SharpYuvConvert、_SharpYuvGetConversionMatrix、_SharpYuvInit符号。
当前配置
WORKSPACE中libwebp源码拉取配置
git_repository( name = "libwebp", remote = "https://chromium.googlesource.com/webm/libwebp", commit = "9ce982fdf21764ef7b273f91d6d72721656c3e03", build_file = "//:bazel/libwebp/BUILD.bazel", )
//:bazel/libwebp/BUILD.bazel
filegroup( name = "srcs", srcs = glob( ["**/*"], exclude = ["bazel*/**"], ), visibility = ["//visibility:public"], )
//:external/libwebp/BUILD.bazel编译配置
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") configure_make( name = "libwebp", autogen = True, configure_in_place = True, configure_options = [], env = select({ "@platforms//os:macos": { "AR": "/usr/bin/ar", }, "//conditions:default": {}, }), lib_source = "@libwebp//:srcs", visibility = ["//visibility:public"], )
go-webp仓库配置
go_repository( name = "com_github_kolesa_team_go_webp", importpath = "github.com/kolesa-team/go-webp", patches = ["//:bazel/com_github_kolesa_team_go_webp/build.patch"], # keep sum = "h1:wQvU4PLG/X7RS0vAeyhiivhLRoxfLVRlDq4I3frdxIQ=", version = "v1.0.4", )
补丁内容
--- encoder/BUILD.bazel +++ encoder/BUILD.bazel @@ -7,7 +7,7 @@ "options.go", ], cgo = True, - clinkopts = ["-lwebp"], + cdeps = ["@asset-tracker//external/libwebp"], importpath = "github.com/kolesa-team/go-webp/encoder", visibility = ["//visibility:public"], )
错误信息
ld: warning: ignoring duplicate libraries: '-lc++', '-lm' Undefined symbols for architecture arm64: "_SharpYuvConvert", referenced from: _PreprocessARGB in libwebp.a[87](libwebpencode_la-picture_csp_enc.o) "_SharpYuvGetConversionMatrix", referenced from: _PreprocessARGB in libwebp.a[87](libwebpencode_la-picture_csp_enc.o) "_SharpYuvInit", referenced from: _ImportYUVAFromRGBA in libwebp.a[87](libwebpencode_la-picture_csp_enc.o) ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) link: error running subcommand external/go_sdk/pkg/tool/darwin_arm64/link: exit status 2
系统信息
Darwin 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:14:38 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6020 arm64 bazel 7.2.1
调试步骤与解决方案
启用libwebp的SharpYuv模块:SharpYuv是libwebp的可选组件,默认未启用。修改
configure_make的configure_options添加启用参数:configure_options = [ "--enable-sharpyuv", ],重新编译后,用以下命令验证符号是否存在:
nm -arch arm64 bazel-bin/external/libwebp/libwebp.a | grep SharpYuv明确指定编译架构:macOS arm64下,需避免架构匹配错误,在
configure_options中添加架构参数:configure_options = [ "--enable-sharpyuv", "--host=aarch64-apple-darwin", ],修正补丁中的依赖路径:补丁中
@asset-tracker//external/libwebp可能与实际工作空间路径不匹配,改为对应libwebp编译目标的正确路径,比如@libwebp//:libwebp。查看编译日志定位问题:添加
--subcommands参数运行Bazel,查看configure和make的具体执行命令,确认SharpYuv模块是否被正确编译:bazel build //your/target --subcommands手动编译验证:拉取指定commit的libwebp源码,执行以下命令手动编译,验证符号是否存在:
./autogen.sh && ./configure --enable-sharpyuv && make nm -arch arm64 libwebp.a | grep SharpYuv若手动编译正常,说明Bazel的
configure_make配置存在遗漏。检查静态库架构兼容性:用以下命令确认生成的libwebp.a是arm64架构:
lipo -info bazel-bin/external/libwebp/libwebp.a
内容的提问来源于stack exchange,提问作者Victor
相关产品推荐
相关产品推荐

