使用clang与libc和c 11从命令行与mac os x

前端之家收集整理的这篇文章主要介绍了使用clang与libc和c 11从命令行与mac os x前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我启用c 11和libc,我很难得到一个简单的hello世界来编译cl声.例如下面的代码
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. std::cout << "Hello,World!" << std::endl;
  6. return 0;
  7. }

当我运行clang -std = c 11 -stdlib = libc main.cpp时,从编译器生成以下输出

  1. In file included from main.cpp:1:
  2. In file included from /usr/bin/../lib/c++/v1/iostream:38:
  3. In file included from /usr/bin/../lib/c++/v1/ios:216:
  4. In file included from /usr/bin/../lib/c++/v1/__locale:15:
  5. In file included from /usr/bin/../lib/c++/v1/string:434:
  6. In file included from /usr/bin/../lib/c++/v1/algorithm:591:
  7. /usr/bin/../lib/c++/v1/type_traits:165:12: error: unknown type name
  8. '_LIBCPP_CONSTEXPR'
  9. static _LIBCPP_CONSTEXPR const _Tp value = __v;
  10. ^
  11. /usr/bin/../lib/c++/v1/type_traits:165:30: error: expected member name or ';'
  12. after declaration specifiers
  13. static _LIBCPP_CONSTEXPR const _Tp value = __v;
  14. ~~~~~~~~~~~~~~~~~~~~~~~~ ^
  15. /usr/bin/../lib/c++/v1/type_traits:169:9: error: unknown type name
  16. '_LIBCPP_CONSTEXPR'
  17. _LIBCPP_CONSTEXPR operator value_type() const {return value;}
  18. ^
  19. /usr/bin/../lib/c++/v1/type_traits:169:63: error: use of undeclared identifier
  20. 'value'
  21. _LIBCPP_CONSTEXPR operator value_type() const {return value;}
  22. ^
  23. /usr/bin/../lib/c++/v1/type_traits:173:1: error: unknown type name
  24. '_LIBCPP_CONSTEXPR'
  25. _LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp,__v>::value;
  26. ^
  27. /usr/bin/../lib/c++/v1/type_traits:173:19: error: expected unqualified-id
  28. _LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp,__v>::value;
  29. ^
  30. /usr/bin/../lib/c++/v1/type_traits:730:2: error: is_base_of not implemented.
  31. #error is_base_of not implemented.
  32. ^
  33. /usr/bin/../lib/c++/v1/type_traits:400:56: error: no member named 'value' in
  34. 'std::__1::is_integral<void>'
  35. : public integral_constant<bool,is_integral<_Tp>::value ||
  36. ~~~~~~~~~~~~~~~~~~^
  37. /usr/bin/../lib/c++/v1/type_traits:941:19: note: in instantiation of template
  38. class 'std::__1::is_arithmetic<void>' requested here
  39. (is_arithmetic<_A2>::value || is_void<_A2>::value) &&
  40. ^
  41. /usr/bin/../lib/c++/v1/type_traits:949:22: note: in instantiation of default
  42. argument for '__promote<type-parameter-0-0,void,void>' required here
  43. typedef typename __promote<_A1>::type __type1;
  44. ^~~~~~~~~~~~~~
  45. /usr/bin/../lib/c++/v1/type_traits:949:38: error: expected a qualified name
  46. after 'typename'
  47. typedef typename __promote<_A1>::type __type1;
  48. ^
  49. /usr/bin/../lib/c++/v1/type_traits:949:42: error: expected ';' at end of
  50. declaration list
  51. typedef typename __promote<_A1>::type __type1;
  52. ^
  53. /usr/bin/../lib/c++/v1/type_traits:941:39: error: no member named 'value' in
  54. 'std::__1::is_arithmetic<void>'
  55. (is_arithmetic<_A2>::value || is_void<_A2>::value) &&
  56. ~~~~~~~~~~~~~~~~~~~~^
  57. /usr/bin/../lib/c++/v1/type_traits:950:22: note: in instantiation of default
  58. argument for '__promote<type-parameter-0-1,void>' required here
  59. typedef typename __promote<_A2>::type __type2;
  60. ^~~~~~~~~~~~~~
  61. /usr/bin/../lib/c++/v1/type_traits:950:38: error: expected a qualified name
  62. after 'typename'
  63. typedef typename __promote<_A2>::type __type2;
  64. ^
  65. /usr/bin/../lib/c++/v1/type_traits:950:42: error: expected ';' at end of
  66. declaration list
  67. typedef typename __promote<_A2>::type __type2;
  68. ^
  69. /usr/bin/../lib/c++/v1/type_traits:941:39: error: no member named 'value' in
  70. 'std::__1::is_arithmetic<void>'
  71. (is_arithmetic<_A2>::value || is_void<_A2>::value) &&
  72. ~~~~~~~~~~~~~~~~~~~~^
  73. /usr/bin/../lib/c++/v1/type_traits:951:38: error: expected a qualified name
  74. after 'typename'
  75. typedef typename __promote<_A3>::type __type3;
  76. ^
  77. /usr/bin/../lib/c++/v1/type_traits:951:42: error: expected ';' at end of
  78. declaration list
  79. typedef typename __promote<_A3>::type __type3;
  80. ^
  81. /usr/bin/../lib/c++/v1/type_traits:953:22: error: use of undeclared identifier
  82. '__type1'
  83. typedef decltype(__type1() + __type2() + __type3()) type;
  84. ^
  85. /usr/bin/../lib/c++/v1/type_traits:953:34: error: use of undeclared identifier
  86. '__type2'
  87. typedef decltype(__type1() + __type2() + __type3()) type;
  88. ^
  89. /usr/bin/../lib/c++/v1/type_traits:953:46: error: use of undeclared identifier
  90. '__type3'
  91. typedef decltype(__type1() + __type2() + __type3()) type;
  92. ^
  93. fatal error: too many errors emitted,stopping now [-ferror-limit=]
  94. 20 errors generated.

如果我使用xcode并设置libc和c 11支持的选项,代码将编译正确.

谢谢你的任何答复

解决方法

您的命令行工具已过期. Clang 4.0附带Xcode 4.4.你想要Clang 4.1,随附Xcode 4.5.安装Xcode后,您可以转到“首选项”窗口,选择“下载”窗格和“组件”选项卡,还有一个“命令行工具”条目.右侧将显示“安装”按钮.

猜你在找的C&C++相关文章