这个错误是因为在 GN 命令 中,--args
参数中的字符串转义(\"
)没有被正确解析,导致 ffmpeg_branding="Chrome"
和 target_cpu="x64"
的引号格式不正确。
解决方案
1. 调整引号转义方式
在 Windows CMD/PowerShell 中:
- 双引号(
"
):需要用反斜杠\
进行转义。 - 但 GN 的参数解析要求更严格,建议改用以下格式:
gn gen out/X64Debug --winsdk="10.0.19041.0" --ide=vs2019 `
--args='ffmpeg_branding="Chrome" rtc_use_h264=true proprietary_codecs=true is_debug=true target_cpu="x64" is_component_build=false use_custom_libcxx=false enable_iterator_debugging=true rtc_enable_protobuf=false'
关键修改点
- 外层用单引号(
'
)包裹整个--args
- PowerShell/CMD 对单引号的字符串处理更直接,避免转义混乱。
- 内部的双引号保持不变
ffmpeg_branding="Chrome"
→ GN 会正确解析内部的" "
。
2. 如果仍然报错
尝试完全移除转义字符,直接传递参数:
gn gen out/X64Debug --winsdk=10.0.19041.0 --ide=vs2019 `
--args="ffmpeg_branding=\"Chrome\" rtc_use_h264=true proprietary_codecs=true is_debug=true target_cpu=\"x64\" is_component_build=false use_custom_libcxx=false enable_iterator_debugging=true rtc_enable_protobuf=false"
- 注意:
确保所有赋值符号(如=
)两侧没有空格(例如rtc_use_h264 = true
→rtc_use_h264=true
)。
3. Linux/macOS 下的写法
如果是 Bash 终端:
gn gen out/X64Debug --winsdk="10.0.19041.0" --ide=vs2019 \
--args='ffmpeg_branding="Chrome" rtc_use_h264=true proprietary_codecs=true is_debug=true target_cpu="x64" is_component_build=false use_custom_libcxx=false enable_iterator_debugging=true rtc_enable_protobuf=false'
4. 验证参数文件
如果命令行复杂,可以改用 args.gn 文件:
在 out/X64Debug/args.gn
中写入:
ffmpeg_branding = "Chrome"
rtc_use_h264 = true
proprietary_codecs = true
is_debug = true
target_cpu = "x64"
is_component_build = false
use_custom_libcxx = false
enable_iterator_debugging = true
rtc_enable_protobuf = false
然后直接运行:
gn gen out/X64Debug --winsdk=10.0.19041.0 --ide=vs2019
常见问题排查
- ERROR: Invalid token
- 检查是否有未闭合的引号或多余的转义符(如
\\Chrome\\
)。
- 检查是否有未闭合的引号或多余的转义符(如
- IDE版本兼容性
- WebRTC官方推荐使用 VS2022(如需最新支持),但VS2019也可用。
- SDK版本问题
- 确保已安装指定的 Windows SDK (
10.0.19041.0
) 。
- 确保已安装指定的 Windows SDK (
如果仍有问题,可以提供完整的错误日志进一步分析!
内容由零声教学AI助手提供,问题来源于学员提问