我在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文件而不是汇编文件并成功编译。
如何解决此问题?非常感谢!
答案 0 :(得分:6)
您的安装有问题。
请在此处找到我的Clang版本: Clang package和required GCC package。 如Clang包下载目录所示,将两者都解压缩到同一目录,并将“mingw32-dw2 / bin”添加到PATH。我测试了你的代码并且它有效。
请注意您的代码有错误:
#include <stdarg.h>
#include <stdio.h>
int main()
{
printf("BAD: %lld\n", 1LL); // NOTE the suffix specifying "long long"
return 0;
}
答案 1 :(得分:0)
观察失败调用的行
“C:/MinGW/bin/gcc.exe”-v -c -m32 -o C:/Users/usrname/AppData/Local/Temp/printf-976142.o -x汇编程序C:/ Users / usrname /AppData/Local/Temp/printf-976141.s
如果我正确阅读了文档,clang默认为AT&amp; T语法,而不是英特尔。对于您的gcc版本,参数可能需要查找缺失/不正确的参数。如果运行成功构建具有优先权,那么或者尝试编译为.o,然后首先链接到llvm的lld的exe,然后gnu的ld秒。