Windows Docker容器中用clang-cl构建LLVM的CMake报错排查求助
Windows Docker容器中LLVM 16二阶段构建clang-cl失败排查方案
问题场景
为满足CI需求,在Windows Docker容器中使用CMake和Ninja构建LLVM 16:
- 第一阶段通过系统MSVC编译器(版本
MSVC 19.29.30154.0)成功构建clang及相关工具 - 第二阶段使用自行构建的
clang-cl.exe构建LLVM时触发报错,核心日志如下:
-- The C compiler identification is unknown -- The CXX compiler identification is unknown -- The ASM compiler identification is unknown -- Found assembler: C:/workdir/llvm-stage-1/bin/clang-cl.exe -- Detecting C compiler ABI info -- Detecting C compiler ABI info - failed -- Check for working C compiler: C:/workdir/llvm-stage-1/bin/clang-cl.exe -- Check for working C compiler: C:/workdir/llvm-stage-1/bin/clang-cl.exe - broken CMake Error at C:/Program Files/CMake/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message): The C compiler "C:/workdir/llvm-stage-1/bin/clang-cl.exe" is not able to compile a simple test program. It fails with the following output: Change Dir: C:/workdir/llvm-stage-2-build/CMakeFiles/CMakeScratch/TryCompile-zn73n4 -- Configuring incomplete, errors occurred! Run Build Command(s): C:/ProgramData/chocolatey/bin/ninja.exe -v cmTC_12e6d CreateProcess failed. Command attempted: "C:\workdir\llvm-stage-1\bin\clang-cl.exe -o CMakeFiles\cmTC_12e6d.dir\testCCompiler.c.obj -c C:\workdir\llvm-stage-2-build\CMakeFiles\CMakeScratch\TryCompile-zn73n4\testCCompiler.c" ninja: fatal: CreateProcess: The system cannot find the path specified.
已确认:路径C:\workdir\llvm-stage-1\bin\clang-cl.exe存在,且已更新容器内ninja、cmake及VS workloads依赖。
排查步骤
- 检查clang-cl.exe的依赖完整性:Windows下clang-cl依赖LLVM动态库(如
libclang.dll、lld.dll等),需和clang-cl.exe在同一目录。用dumpbin /dependents C:\workdir\llvm-stage-1\bin\clang-cl.exe查看依赖列表,确认所有dll都存在。 - 验证Ninja的可用性与权限:直接执行
C:/ProgramData/chocolatey/bin/ninja.exe --version验证Ninja可运行;检查Ninja对clang-cl目录、临时构建目录的读写权限。 - 手动执行测试编译命令:直接在容器中运行报错里的编译命令:
观察具体错误提示,判断是依赖缺失还是权限问题。"C:\workdir\llvm-stage-1\bin\clang-cl.exe" -o CMakeFiles\cmTC_12e6d.dir\testCCompiler.c.obj -c C:\workdir\llvm-stage-2-build\CMakeFiles\CMakeScratch\TryCompile-zn73n4\testCCompiler.c - 调整CMake编译配置参数:第二阶段构建时添加参数跳过自动检测、明确指定编译器:
cmake -G Ninja -DCMAKE_C_COMPILER=clang-cl.exe -DCMAKE_CXX_COMPILER=clang-cl.exe -DCMAKE_C_COMPILER_FORCED=ON -DCMAKE_CXX_COMPILER_FORCED=ON ... - 检查VS环境变量加载状态:第二阶段构建前手动加载VS环境脚本,如:
确保"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\VsDevCmd.bat"INCLUDE、LIB、PATH等环境变量正确配置。 - 排查路径转义问题:尝试用短路径格式指定编译器(通过
dir /x获取短路径),或在CMake命令中用双引号包裹路径,避免解析错误。
内容的提问来源于stack exchange,提问作者snpefk
相关产品推荐
相关产品推荐

