当使用stdlibc ++ 4.7启用C ++ 11时,clang错误输出,而gcc编译正常 [英] When enabling C++11 with stdlibc++ 4.7, clang error out, while gcc compiles fine

查看:1042
本文介绍了当使用stdlibc ++ 4.7启用C ++ 11时,clang错误输出,而gcc编译正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图让C ++ 11工作,浏览不同的网站和Q / A后,我仍然有麻烦。我想使用clang与libstdc ++。它在clang状态中指示其支持修补程序 - http://clang.llvm.org/libstdc+ + 4.7-clang11.patch 。我从macports下载gcc4.7并在gcc4.7的头文件做相应的更改



我不使用libc ++的原因是libc ++和libc ++之间的ABI兼容性libstdc ++,由此线程指示:为什么不能在c ++ 0x模式中使用libc ++链接此boost :: program_options示例?



好的,一切完成后,我测试我的设置使用以下代码:

  #include< mutex> 
#include< thread>

int main(){
std :: mutex myMutext;
return 0;
}



我希望include应该在c ++ 11下工作。



下面是我如何编译它:
with GCC

  g ++ -std = c ++ 11 -I / opt / local / include / gcc47 / c ++ -L / opt / local / lib / gcc47 main.cpp -o main 
pre>

用Clang

成功编译





  clang ++ -std = c ++ 11 -I / opt / local / include / gcc47 / c ++ -L / opt / local / lib / gcc47 main.cpp -o main 

我收到此错误:

  @work:boostTest $ clang ++ -std = c ++ 11 -I / opt / local / include / gcc47 / c ++ -L / opt / local / lib / gcc47 main.cpp -o main 
文件包括从main.cpp:1:
在/ opt / local / include / gcc47 / c ++ / mutex中包含的文件:
在/ opt / local / include / gcc47 / c ++ / tuple:37:
在/ opt / local / include / gcc47 / c ++ / utility:70中包含的文件中:
/opt/local/include/gcc47/c++/bits/stl_relops.h:72 :3:错误:未知类型名称'_GLIBCXX_BEGIN_NAMESPACE_VERSION'
_GLIBCXX_BEGIN_NAMESPACE_VERSION
^
/opt/local/include/gcc47/c++/bits/stl_relops.h:86:5:错误:预期不合格-id
template< class _Tp>
^
在main.cpp中包含的文件中:1:
在/ opt / local / include / gcc47 / c ++ / mutex中包含的文件中:
/ opt / local / include / gcc47 / c ++ / tuple:37:
在/ opt / local / include / gcc47 / c ++ / utility:71中包含的文件:
在/ opt / local /include/gcc47/c++/bits/stl_pair.h:61:
/opt/local/include/gcc47/c++/bits/move.h:38:1:错误:未知类型名称'_GLIBCXX_BEGIN_NAMESPACE_VERSION'
_GLIBCXX_BEGIN_NAMESPACE_VERSION
^
/opt/local/include/gcc47/c++/bits/move.h:45:3:错误:expected unqualified-id
template< typename _Tp>
^
在main.cpp中包含的文件中:1:
在/ opt / local / include / gcc47 / c ++ / mutex中包含的文件中:
/ opt / local / include / gcc47 / c ++ / tuple:37:
在/ opt / local / include / gcc47 / c ++ / utility:71中包含的文件:
在/ opt / local /include/gcc47/c++/bits/stl_pair.h:61:
在/opt/local/include/gcc47/c++/bits/move.h:57中包含的文件中:
/ opt / local / include / gcc47 / c ++ / type_traits:41:1:错误:未知类型名称'_GLIBCXX_BEGIN_NAMESPACE_VERSION'
_GLIBCXX_BEGIN_NAMESPACE_VERSION
^
/ opt / local / include / gcc47 / c ++ / type_traits: 3:error:expected unqualified-id
template< typename _Tp,_Tp __v>
^
/ opt / local / include / gcc47 / c ++ / type_traits:65:11:错误:未知类型名称'integral_constant'
typedef integral_constant< bool,true> true_type;
^
/ opt / local / include / gcc47 / c ++ / type_traits:65:28:error:expected unqualified-id
typedef integral_constant< bool,true& true_type;
^
/ opt / local / include / gcc47 / c ++ / type_traits:68:11:错误:未知类型名称'integral_constant'
typedef integral_constant< bool,false> false_type;
^
/ opt / local / include / gcc47 / c ++ / type_traits:68:28:error:expected unqualified-id
typedef integral_constant< bool,false> false_type;
^
/ opt / local / include / gcc47 / c ++ / type_traits:71:36:错误:期望在顶层声明器之后的';'
constexpr _Tp integral_constant< _Tp,__v>值;
^
/ opt / local / include / gcc47 / c ++ / type_traits:83:14:error:期望的类名
:public false_type
^
/ opt / local / include / gcc47 / c ++ / type_traits:106:14:错误:期望的类名
:public true_type
^
/ opt / local / include / gcc47 / c ++ / type_traits: 14:错误:未知的模板名称integral_constant
:public integral_constant< bool,!_Pp :: value>
^
/ opt / local / include / gcc47 / c ++ / type_traits:126:38:error:expected class name
:public integral_constant< bool,!_Pp :: value&
^
/ opt / local / include / gcc47 / c ++ / type_traits:142:14:error:expected class name
:public false_type {};
^
/ opt / local / include / gcc47 / c ++ / type_traits:146:14:error:expected class name
:public true_type {};
^
/ opt / local / include / gcc47 / c ++ / type_traits:151:14:错误:未知模板名称integral_constant
:public integral_constant< bool,(__is_void_helper< typename
^
/ opt / local / include / gcc47 / c ++ / type_traits:151:38:error:expected class name
:public integral_constant< bool,(__is_void_helper< typename
^
致命错误:发出错误太多,现在停止[-ferror-limit =]
生成20个错误


b $ b

我使用clang版本:

  Apple clang版本4.0(tags / Apple / clang-418.2.41 )(基于LLVM 3.1svn)
目标:x86_64-apple-darwin11.3.0
线程模型:posix

我做错了什么?或者这是最新的gcc 4.7 libstc ++的铛问题?

解决方案

你为什么要说 -I / opt / local / include / gcc47 / c ++



需要与GCC或Clang,并且不会工作。不是所有的libstdc ++头都在那个路径下,有一些必要的头文件定义了 _GLIBCXX_BEGIN_NAMESPACE_VERSION



因为GCC已经知道如何找到其他头部,所以使用 -I -L 选项。它不能与Clang工作,因为你只是告诉它如何找到一些所需的头,但不告诉它如何找到其余的。



停止尝试重写编译器的标准库路径,让它使用它已经知道的内置路径。


I have been trying to get C++11 to work, after browsing different websites and Q/A, i am still having trouble with. I want to use clang with libstdc++. It is indicated in the clang status that it's supported with patch - http://clang.llvm.org/libstdc++4.7-clang11.patch. I download the gcc4.7 from macports and made corresponding changes in the headers for gcc4.7

The reason that i don't uses libc++ is because ABI compatibilities between libc++ and libstdc++, indicated by this thread: Why can't clang with libc++ in c++0x mode link this boost::program_options example?

OK, after everything is done, i tested my setup with the following code:

#include <mutex>
#include <thread>

int main ( ) {
    std::mutex myMutext;
    return 0;
}

I am expecting that include should work under c++11.

So here is how I compile it with: with GCC

g++ -std=c++11 -I/opt/local/include/gcc47/c++ -L/opt/local/lib/gcc47 main.cpp -o main

Compile successfully

with Clang

clang++ -std=c++11 -I/opt/local/include/gcc47/c++ -L/opt/local/lib/gcc47 main.cpp -o main

I am getting this error:

@work:boostTest$ clang++ -std=c++11 -I/opt/local/include/gcc47/c++ -L/opt/local/lib/gcc47 main.cpp -o main
In file included from main.cpp:1:
In file included from /opt/local/include/gcc47/c++/mutex:38:
In file included from /opt/local/include/gcc47/c++/tuple:37:
In file included from /opt/local/include/gcc47/c++/utility:70:
/opt/local/include/gcc47/c++/bits/stl_relops.h:72:3: error: unknown type name '_GLIBCXX_BEGIN_NAMESPACE_VERSION'
  _GLIBCXX_BEGIN_NAMESPACE_VERSION
  ^
/opt/local/include/gcc47/c++/bits/stl_relops.h:86:5: error: expected unqualified-id
    template <class _Tp>
    ^
In file included from main.cpp:1:
In file included from /opt/local/include/gcc47/c++/mutex:38:
In file included from /opt/local/include/gcc47/c++/tuple:37:
In file included from /opt/local/include/gcc47/c++/utility:71:
In file included from /opt/local/include/gcc47/c++/bits/stl_pair.h:61:
/opt/local/include/gcc47/c++/bits/move.h:38:1: error: unknown type name '_GLIBCXX_BEGIN_NAMESPACE_VERSION'
_GLIBCXX_BEGIN_NAMESPACE_VERSION
^
/opt/local/include/gcc47/c++/bits/move.h:45:3: error: expected unqualified-id
  template<typename _Tp>
  ^
In file included from main.cpp:1:
In file included from /opt/local/include/gcc47/c++/mutex:38:
In file included from /opt/local/include/gcc47/c++/tuple:37:
In file included from /opt/local/include/gcc47/c++/utility:71:
In file included from /opt/local/include/gcc47/c++/bits/stl_pair.h:61:
In file included from /opt/local/include/gcc47/c++/bits/move.h:57:
/opt/local/include/gcc47/c++/type_traits:41:1: error: unknown type name '_GLIBCXX_BEGIN_NAMESPACE_VERSION'
_GLIBCXX_BEGIN_NAMESPACE_VERSION
^
/opt/local/include/gcc47/c++/type_traits:55:3: error: expected unqualified-id
  template<typename _Tp, _Tp __v>
  ^
/opt/local/include/gcc47/c++/type_traits:65:11: error: unknown type name 'integral_constant'
  typedef integral_constant<bool, true>     true_type;
          ^
/opt/local/include/gcc47/c++/type_traits:65:28: error: expected unqualified-id
  typedef integral_constant<bool, true>     true_type;
                           ^
/opt/local/include/gcc47/c++/type_traits:68:11: error: unknown type name 'integral_constant'
  typedef integral_constant<bool, false>    false_type;
          ^
/opt/local/include/gcc47/c++/type_traits:68:28: error: expected unqualified-id
  typedef integral_constant<bool, false>    false_type;
                           ^
/opt/local/include/gcc47/c++/type_traits:71:36: error: expected ';' after top level declarator
    constexpr _Tp integral_constant<_Tp, __v>::value;
                                   ^
/opt/local/include/gcc47/c++/type_traits:83:14: error: expected class name
    : public false_type
             ^
/opt/local/include/gcc47/c++/type_traits:106:14: error: expected class name
    : public true_type
             ^
/opt/local/include/gcc47/c++/type_traits:126:14: error: unknown template name 'integral_constant'
    : public integral_constant<bool, !_Pp::value>
             ^
/opt/local/include/gcc47/c++/type_traits:126:38: error: expected class name
    : public integral_constant<bool, !_Pp::value>
                                     ^
/opt/local/include/gcc47/c++/type_traits:142:14: error: expected class name
    : public false_type { };
             ^
/opt/local/include/gcc47/c++/type_traits:146:14: error: expected class name
    : public true_type { };
             ^
/opt/local/include/gcc47/c++/type_traits:151:14: error: unknown template name 'integral_constant'
    : public integral_constant<bool, (__is_void_helper<typename
             ^
/opt/local/include/gcc47/c++/type_traits:151:38: error: expected class name
    : public integral_constant<bool, (__is_void_helper<typename
                                     ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

I am using clang version:

Apple clang version 4.0 (tags/Apple/clang-418.2.41) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.3.0
Thread model: posix

Am I doing something wrong? or is this a clang problem with latest gcc 4.7 libstc++?

解决方案

Why are you saying -I/opt/local/include/gcc47/c++ ?

That should not be necessary with either GCC or Clang, and will not work. Not all libstdc++ headers are under that path, there are some essential headers elsewhere that define things like _GLIBCXX_BEGIN_NAMESPACE_VERSION

It doesn't fail with GCC because GCC already knows how to find the other headers, so it's redundant to explicitly use -I and -L options. It doesn't work with Clang because you are only telling it how to find some of the headers it needs, but not telling it how to find the rest.

Stop trying to override the compiler's standard library paths, let it use the built-in paths it already knows about.

这篇关于当使用stdlibc ++ 4.7启用C ++ 11时,clang错误输出,而gcc编译正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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