我在Clang 3.4中遇到了一个相当棘手的编译问题。Clang 3.2的代码编译得很好,但我想尝试一下Clang 3.4上的一些前沿功能。
我按照这里的说明安装了Clang 3.4。
有人知道Clang为什么抱怨stdlib.h吗?我使用的是鲁本图13.04。
Clang 3.2的输出-
clang -v -g -fsanitize=address -fno-omit-frame-pointer -fms-extensions -O0 -o obj/Test.o -Iinc/ -c Test.c
Ubuntu clang version 3.2-1~exp9ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)
Target: i386-pc-linux-gnu
Thread model: posix
"/usr/bin/clang" -cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name Test.c -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu pentium4 -target-linker-version 2.23.2 -momit-leaf-frame-pointer -v -g -coverage-file /home/adminuser/project/obj/Test.o -resource-dir /usr/bin/../lib/clang/3.2 -I inc/ -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.2/include -internal-isystem /usr/include/clang/3.2/include/ -internal-externc-isystem /usr/include/i386-linux-gnu -internal-externc-isystem /usr/include/i686-linux-gnu -internal-externc-isystem /usr/include -O0 -fdebug-compilation-dir /home/adminuser/project -ferror-limit 19 -fmessage-length 0 -fsanitize=address -mstackrealign -fms-extensions -fmsc-version=1300 -fobjc-runtime=gcc -fdiagnostics-show-option -o obj/Test.o -x c Test.c
clang -cc1 version 3.2 based upon LLVM 3.2svn default target i386-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/clang/3.2/include"
ignoring nonexistent directory "/usr/include/i686-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
inc
/usr/local/include
/usr/include/clang/3.2/include
/usr/include/i386-linux-gnu
/usr/include
Clang 3.4的输出-
clang -v -g -fsanitize=address -fno-omit-frame-pointer -fms-extensions -O0 -o obj/Test.o -Iinc/ Test.c
Ubuntu clang version 3.4-1~exp1 (trunk) (based on LLVM 3.4)
Target: i386-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.7
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.7.3
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.8.1
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.7.3
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8.1
Selected GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8
"/usr/bin/clang" -cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name Test.c -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu pentium4 -target-linker-version 2.23.2 -v -g -coverage-file /home/adminuser/project/obj/Test.o -resource-dir /usr/bin/../lib/clang/3.4 -I inc/ -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.4/include -internal-isystem /usr/include/clang/3.4/include/ -internal-externc-isystem /usr/include/i386-linux-gnu -internal-externc-isystem /usr/include/i686-linux-gnu -internal-externc-isystem /usr/include -O0 -fdebug-compilation-dir /home/adminuser/BuildFW/test/GlassCubeAssembler_C -ferror-limit 19 -fmessage-length 0 -fsanitize=address,init-order -mstackrealign -fms-extensions -fmsc-version=1300 -fobjc-runtime=gcc -fobjc-default-synthesize-properties -fdiagnostics-show-option -vectorize-slp -o obj/Test.o -x c Test.c
clang -cc1 version 3.4 based upon LLVM 3.4 default target i386-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/clang/3.4/include"
ignoring nonexistent directory "/usr/include/i686-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
inc
/usr/local/include
/usr/include/clang/3.4/include
/usr/include/i386-linux-gnu
/usr/include
End of search list.
In file included from Test.c:4:
/usr/include/stdlib.h:69:23: error: expected member name or ';' after declaration specifiers
union wait *__uptr;
~~~~~ ^
1 error generated.
问题是您使用的是-fms-extensions
,它支持MS扩展,包括__uptr
关键字。在stdlib.h
内部,__uptr
用作标识符:
联合等待*__uptr;
这与MS扩展不兼容。
Alp Toker在上游r195710的clang主干中添加了一个解决方法,该修复将在clang 3.4版本中进行。
这是http://llvm.org/PR17824并由Alp-Toker在Clang r195710中固定:http://llvm.org/viewvc/llvm-project?rev=195710&view=rev