当WebRTC m84 遇上 Xcode 12.5

在Mac上编译WebRTC m84时遇到编译错误,原因是Xcode 12.5的工具链不兼容。解决方案包括更改工具链为macos系统工具链,或者升级WebRTC的llvm-build工具链。通过本地编译llvm或下载预编译版本,可以成功解决编译问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

最近,多位同事在 Mac 端编译 Android 平台的 WebRTC(m84版本)的时遇到了编译错误:

FAILED: clang_x64/obj/third_party/ijar/ijar/ijar.o 
../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF clang_x64/obj/third_party/ijar/ijar/ijar.o.d -D_LIBCPP_HAS_NO_ALIGNED_ALLOCATION -DCR_XCODE_VERSION=1250 -DCR_CLANG_REVISION=\"n353803-99ac9ce7-1\" -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -I../.. -Iclang_x64/gen -I../../third_party/zlib -fno-strict-aliasing -fstack-protector -fcolor-diagnostics -fmerge-all-constants -fcrash-diagnostics-dir=../../tools/clang/crashreports -Xclang -mllvm -Xclang -instcombine-lower-dbg-declare=0 -arch x86_64 -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -Xclang -fdebug-compilation-dir -Xclang . -no-canonical-prefixes -Wall -Werror -Wextra -Wimplicit-fallthrough -Wunreachable-code -Wthread-safety -Wunguarded-availability -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-unneeded-internal-declaration -Wno-unused-private-field -Wno-unused-variable -Wno-undefined-var-template -Wno-ignored-pragma-optimize -Wno-implicit-int-float-conversion -Wno-final-dtor-non-final-class -Wno-builtin-assume-aligned-alignment -Wno-deprecated-copy -Wno-non-c-typedef-for-linkage -O2 -fno-omit-frame-pointer -gdwarf-4 -g2 -Xclang -debug-info-kind=constructor -isysroot ../../../../../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -mmacosx-version-min=10.10.0 -ftrivial-auto-var-init=pattern -fvisibility=hidden -Xclang -add-plugin -Xclang find-bad-constructs -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -std=c++14 -stdlib=libc++ -fno-exceptions -fvisibility-inlines-hidden -c ../../third_party/ijar/ijar.cc -o clang_x64/obj/third_party/ijar/ijar/ijar.o
In file included from ../../third_party/ijar/ijar.cc:21:
../../third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/stdlib.h:142:34: error: unknown type name 'ldiv_t'
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
                                 ^
../../third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/stdlib.h:143:12: error: no member named 'ldiv' in the global namespace
  return ::ldiv(__x, __y);
         ~~^
../../third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/stdlib.h:146:34: error: unknown type name 'lldiv_t'
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,

...

../../third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/wchar.h:157:93: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'const wchar_t *'
wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);}
                                                                                            ^~~~
../../third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/wchar.h:140:38: note: passing argument to parameter '__s' here
      wchar_t* wcschr(      wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);}
                                     ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
ninja: build stopped: subcommand failed.

WebRTC的Android平台编译需要用 mac 工具链编译 ijar 可执行文件,用于将java文件打包成 jar或将jar库进行拆解。经过对比判断,同事升级了Xcode 12.5(clang-1205.0.22.9),而我本机仍是 Xcode 12.4(clang-1200.0.32.29),WebRTC m84的工具链llvm-build(clang 11.0.0)。在同事把头文件目录 third_party/llvm-build/Release+Asserts/bin/…/include 重命名 include_bk后,编译通过,可以基本确定是工具链问题导致,毕竟众所周知,苹果的Xcode升级经常会有各种兼容问题。但该方法经验证,在 Xcode 12.4 环境会编译失败,即该解决方法并不能通用,需要查找新的解决方法。
所以,便有了以下两个预案:

    1. 弃用 llvm-build 工具链,改用 macos 系统的工具链;
    1. 升级 WebRTC 的llvm-build工具链。

接下来,我们一一尝试。

1 更改工具链

经过对编译脚本的分析,修改了以下几个文件,将 WebRTC m84的工具链从 llvm-build 切换到系统的 clang 工具链:

diff --git a/build/config/clang/BUILD.gn b/build/config/clang/BUILD.gn
ol
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值