在 CMake 和 MinGW 的帮助下,我在 Windows 上构建了 LLVM 和 Clang(3.2 版)。该建筑简单而成功。但是,Clang 无法使用示例代码。
#include <stdarg.h>
#include <stdio.h>
int main()
{
printf("BAD: %lld\n", 1);
return 0;
}
当我用clang编译它时
clang -o printf.exe printf.c -v
在 Windows 上,它失败并显示消息
clang version 3.2 (branches/release_32 172788)
Target: i686-pc-mingw32
Thread model: posix
"D:/llvm/Build/bin/clang.exe" -cc1 -triple i686-pc-mingw32 -S -disable-free -main-file-name printf.c -mrelocation-model static -mdisable-fp-elim -fmath-errno -mconstructor-aliases -target-cpu pentium4 -momit-leaf-frame-pointer -v -resource-dir "D:/llvm/Build/bin\\..\\lib\\clang\\3.2" -fmodule-cache-path "C:\\Users\\usrname\\AppData\\Local\\Temp\\clang-module-cache" -fno-dwarf-directory-asm -ferror-limit 19 -fmessage-length 140 -mstackrealign -fno-use-cxa-atexit -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o C:/Users/usrname/AppData/Local/Temp/printf-976141.s -x c printf.c
clang -cc1 version 3.2 based upon LLVM 3.2svn default target i686-pc-mingw32
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "D:/llvm/Build/bin/../lib/clang/3.2/../../../i686-w64-mingw32/include"
ignoring nonexistent directory "D:/llvm/Build/bin/../lib/clang/3.2/../../../x86_64-w64-mingw32/include"
ignoring nonexistent directory "/mingw/include"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include search starts here:
D:/llvm/Build/bin/../lib/clang/3.2/include
D:/llvm/Build/bin/../lib/clang/3.2/../../../include
c:/mingw/include
End of search list.
printf.c:6:24: warning: format specifies type 'long long' but the argument has type 'int' [-Wformat]
printf("BAD: %lld\n", 1);
~~~~ ^
%d
1 warning generated.
"C:/MinGW/bin/gcc.exe" -v -c -m32 -o C:/Users/usrname/AppData/Local/Temp/printf-976142.o -x assembler C:/Users/usrname/AppData/Local/Temp/printf-976141.s
Using built-in specs.
COLLECT_GCC=C:/MinGW/bin/gcc.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.1/configure --enable-languages=c,c++,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.1 (GCC)
COLLECT_GCC_OPTIONS='-v' '-c' '-m32' '-o' 'C:/Users/usrname/AppData/Local/Temp/printf-976142.o' '-mtune=i386' '-march=i386'
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/bin/as.exe -o C:/Users/usrname/AppData/Local/Temp/printf-976142.o C:/Users/usrname/AppData/Local/Temp/printf-976141.s
C:/Users/usrname/AppData/Local/Temp/printf-976141.s: Assembler messages:
C:/Users/usrname/AppData/Local/Temp/printf-976141.s:7: Error: bad expression
C:/Users/usrname/AppData/Local/Temp/printf-976141.s:7: Error: junk at end of line, first unrecognized character is `\'
clang: error: assembler (via gcc) command failed with exit code 1 (use -v to see invocation)
生成的临时汇编文件为:
.def _main;
.scl 2;
.type 32;
.endef
.text
.globl _main
.align 16, 0x90, "\357\276\255\336"
_main:
Windows 上的 Clang 似乎生成了错误格式的汇编文件。但是在Linux上,它直接生成一个obejct文件而不是一个汇编文件并成功编译。
我该如何解决这个问题?非常感谢!