以下代码
#include <iostream>
int main(void)
{
std::cout << "Hello World!" << std::endl;
return 0;
}
使用g ++和clang编译好
g++ test.cpp
clang -I /usr/lib/gcc/x86_64-linux-gnu/4.7/include -I /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed -lstdc++ test.cpp
其中/usr/lib/gcc/x86_64-linux-gnu/4.7/
指向libstdc ++
但是,当我添加额外的#include <emmintrin.h>
clang汇编失败
In file included from test.cpp:2:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/include/emmintrin.h:36:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/include/xmmintrin.h:36:
/usr/lib/gcc/x86_64-linux-gnu/4.7/include/mmintrin.h:46:72: warning: unknown attribute '__artificial__' ignored [-Wunknown-attributes]
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
^
/usr/lib/gcc/x86_64-linux-gnu/4.7/include/mmintrin.h:52:72: warning: unknown attribute '__artificial__' ignored [-Wunknown-attributes]
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
...
/usr/lib/gcc/x86_64-linux-gnu/4.7/include/xmmintrin.h:120:19: error: use of undeclared identifier '__builtin_ia32_divss'; did you mean '__builtin_ia32_minss'?
return (__m128) __builtin_ia32_divss ((__v4sf)__A, (__v4sf)__B);
...
根据http://en.cppreference.com/w/cpp/header,`xmmintrin.h'不是标准C ++库接口的一部分,因此我猜它包含Gnu特定的东西。我可以用clang编译这段代码吗?
如果没有,我怎样才能轻松安装clang libc ++?
sudo aptitude install libc++-dev
找不到包(虽然这在Ubuntu 16.04上有效)
我正在使用
"Debian GNU/Linux 7 (wheezy)"
gcc version 4.7.2 (Debian 4.7.2-5) // Target: x86_64-linux-gnu
clang version 3.6.0 (trunk 224504) // Target: x86_64-unknown-linux-gnu
答案 0 :(得分:0)
显然,我的clang安装不完整。
下载llvm和clang(v3.7.1,因为v4.0.1需要gcc4.8而我只有4.7)并在本地构建它clang -lstdc++ test.cpp
在这两种情况下都能正常工作。