C++ Windows上的Clang无法编译代码
在CMake和MinGW的帮助下,我在Windows上构建了LLVM和Clang(3.2版)。这座建筑既简单又成功。但是,Clang无法处理示例代码C++ Windows上的Clang无法编译代码,c++,mingw,llvm,clang,C++,Mingw,Llvm,Clang,在CMake和MinGW的帮助下,我在Windows上构建了LLVM和Clang(3.2版)。这座建筑既简单又成功。但是,Clang无法处理示例代码 #include <stdarg.h> #include <stdio.h> int main() { printf("BAD: %lld\n", 1); return 0; } 在Windows上,它失败并显示消息 clang version 3.2 (branches/release_32
#include <stdarg.h>
#include <stdio.h>
int main()
{
printf("BAD: %lld\n", 1);
return 0;
}
在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上的叮当声似乎生成了错误格式的汇编文件。
但在Linux上,它直接生成一个obejct文件而不是汇编文件,并成功编译
我如何解决这个问题?非常感谢 您的安装有问题 请在此处找到我的Clang版本: 和。 如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;
}
#包括
#包括
int main()
{
printf(“错误:%lld\n”,1LL);//注意指定“long-long”的后缀
返回0;
}
观察失败调用的行
“C:/MinGW/bin/gcc.exe”-v-C-m32-oc:/Users/usrname/AppData/Local/Temp/printf-976142.o-x汇编程序C:/Users/usrname/AppData/Local/Temp/printf-976141.s
如果我正确阅读了文档,那么clang默认为AT&T语法,而不是Intel。对于您的gcc版本,可能需要查找缺少/不正确的参数。如果运行成功的构建有优先权,则可选择尝试编译为.O,然后链接到一个带有LLVM LLD的EXE,然后是GNU的LD秒。如果您关心支持多个编译器,请考虑使用STNDET.H宏为文字:InxxFixC(n)和UnTxxxC(n),其中XX是8, 16, 32、64和MAX.中的一个,如果您有ItPyType h,您也可以像这样使用PRId64:
printf(“BAD:“PRId64”\n”,INT64_C(1))
更便于移植64位数字的格式字符串。但这不太可能得到广泛支持。示例代码故意包含一个潜在的bug。我正在尝试你的解决方案。谢谢谢谢你的二进制文件。我尝试了(标记为“实验性”),但在基本行上出现了错误,如#include
#include <stdarg.h>
#include <stdio.h>
int main()
{
printf("BAD: %lld\n", 1LL); // NOTE the suffix specifying "long long"
return 0;
}