使用clang与libc ++和c ++ 11从命令行与mac os x [英] Using clang with libc++ and c++11 from the command line with mac os x

查看:668
本文介绍了使用clang与libc ++和c ++ 11从命令行与mac os x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我启用c ++ 11和libc ++,我无法获得一个简单的hello世界编译clang。例如以下代码

I am having trouble getting even a simple hello world to compile with clang if I enable c++11 and libc++. For example the following code

#include <iostream>

int main()
{
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

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

In file included from main.cpp:1:
In file included from /usr/bin/../lib/c++/v1/iostream:38:
In file included from /usr/bin/../lib/c++/v1/ios:216:
In file included from /usr/bin/../lib/c++/v1/__locale:15:
In file included from /usr/bin/../lib/c++/v1/string:434:
In file included from /usr/bin/../lib/c++/v1/algorithm:591:
/usr/bin/../lib/c++/v1/type_traits:165:12: error: unknown type name
      '_LIBCPP_CONSTEXPR'
    static _LIBCPP_CONSTEXPR const _Tp      value = __v;
           ^
/usr/bin/../lib/c++/v1/type_traits:165:30: error: expected member name or ';'
      after declaration specifiers
    static _LIBCPP_CONSTEXPR const _Tp      value = __v;
    ~~~~~~~~~~~~~~~~~~~~~~~~ ^
/usr/bin/../lib/c++/v1/type_traits:169:9: error: unknown type name
      '_LIBCPP_CONSTEXPR'
        _LIBCPP_CONSTEXPR operator value_type() const {return value;}
        ^
/usr/bin/../lib/c++/v1/type_traits:169:63: error: use of undeclared identifier
      'value'
        _LIBCPP_CONSTEXPR operator value_type() const {return value;}
                                                              ^
/usr/bin/../lib/c++/v1/type_traits:173:1: error: unknown type name
      '_LIBCPP_CONSTEXPR'
_LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value;
^
/usr/bin/../lib/c++/v1/type_traits:173:19: error: expected unqualified-id
_LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value;
                  ^
/usr/bin/../lib/c++/v1/type_traits:730:2: error: is_base_of not implemented.
#error is_base_of not implemented.
 ^
/usr/bin/../lib/c++/v1/type_traits:400:56: error: no member named 'value' in
      'std::__1::is_integral<void>'
    : public integral_constant<bool, is_integral<_Tp>::value      ||
                                     ~~~~~~~~~~~~~~~~~~^
/usr/bin/../lib/c++/v1/type_traits:941:19: note: in instantiation of template
      class 'std::__1::is_arithmetic<void>' requested here
                 (is_arithmetic<_A2>::value || is_void<_A2>::value) &&
                  ^
/usr/bin/../lib/c++/v1/type_traits:949:22: note: in instantiation of default
      argument for '__promote<type-parameter-0-0, void, void>' required here
    typedef typename __promote<_A1>::type __type1;
                     ^~~~~~~~~~~~~~
/usr/bin/../lib/c++/v1/type_traits:949:38: error: expected a qualified name
      after 'typename'
    typedef typename __promote<_A1>::type __type1;
                                     ^
/usr/bin/../lib/c++/v1/type_traits:949:42: error: expected ';' at end of
      declaration list
    typedef typename __promote<_A1>::type __type1;
                                         ^
/usr/bin/../lib/c++/v1/type_traits:941:39: error: no member named 'value' in
      'std::__1::is_arithmetic<void>'
                 (is_arithmetic<_A2>::value || is_void<_A2>::value) &&
                  ~~~~~~~~~~~~~~~~~~~~^
/usr/bin/../lib/c++/v1/type_traits:950:22: note: in instantiation of default
      argument for '__promote<type-parameter-0-1, void, void>' required here
    typedef typename __promote<_A2>::type __type2;
                     ^~~~~~~~~~~~~~
/usr/bin/../lib/c++/v1/type_traits:950:38: error: expected a qualified name
      after 'typename'
    typedef typename __promote<_A2>::type __type2;
                                     ^
/usr/bin/../lib/c++/v1/type_traits:950:42: error: expected ';' at end of
      declaration list
    typedef typename __promote<_A2>::type __type2;
                                         ^
/usr/bin/../lib/c++/v1/type_traits:941:39: error: no member named 'value' in
      'std::__1::is_arithmetic<void>'
                 (is_arithmetic<_A2>::value || is_void<_A2>::value) &&
                  ~~~~~~~~~~~~~~~~~~~~^
/usr/bin/../lib/c++/v1/type_traits:951:38: error: expected a qualified name
      after 'typename'
    typedef typename __promote<_A3>::type __type3;
                                     ^
/usr/bin/../lib/c++/v1/type_traits:951:42: error: expected ';' at end of
      declaration list
    typedef typename __promote<_A3>::type __type3;
                                         ^
/usr/bin/../lib/c++/v1/type_traits:953:22: error: use of undeclared identifier
      '__type1'
    typedef decltype(__type1() + __type2() + __type3()) type;
                     ^
/usr/bin/../lib/c++/v1/type_traits:953:34: error: use of undeclared identifier
      '__type2'
    typedef decltype(__type1() + __type2() + __type3()) type;
                                 ^
/usr/bin/../lib/c++/v1/type_traits:953:46: error: use of undeclared identifier
      '__type3'
    typedef decltype(__type1() + __type2() + __type3()) type;
                                             ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

如果我使用xcode并设置libc ++和c ++ 11支持的选项,代码将编译得很好

The code will compile fine if I use xcode and set the options for libc++ and c++11 support.

感谢您的回复

推荐答案

工具已过期。 Clang 4.0随Xcode 4.4一起提供。你想要的Clang 4.1,它附带Xcode 4.5。安装Xcode后,您可以转到首选项窗口,选择下载窗格和组件选项卡,并有一个条目命令行工具。在右侧会有一个按钮安装。

Your command-line tools are out of date. Clang 4.0 shipped with Xcode 4.4. You want Clang 4.1, which ships with Xcode 4.5. After installing Xcode, you can go to the Preferences window, select the Downloads pane, and the Components tab, and there's an entry for "Command Line Tools". There will be a button on the right side that says "Install".

这篇关于使用clang与libc ++和c ++ 11从命令行与mac os x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆