当与stdlibc ++ 4.7,铛错误输出,使C ++ 11而GCC编译细(When enabli

2019-06-23 22:56发布

我一直在试图让C ++ 11的工作,浏览不同的网站和Q / A,我仍然有麻烦了。 我想用铿锵用的libstdc ++。 -这是在它的补丁支持铛状态指示http://clang.llvm.org/libstdc++4.7-clang11.patch 。 我下载的MacPorts从该gcc4.7和取得的标头gcc4.7相应的变化

我不之所以使用的libc ++是因为libc中之间ABI兼容性++和libstdc ++,通过这个线程指出: 为什么不能用的libc ++中的C ++ 0x模式链接此的boost :: program_options例如铛?

OK,万事俱备后,我测试了我的设置与下面的代码:

#include <mutex>
#include <thread>

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

我期待,其中包括在C ++ 11应该工作。

因此,这里是我如何与编译:与GCC

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

成功编译

铿锵

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
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.

我使用铛版本:

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

难道我做错了什么? 或者这是一个铿锵问题,最新的gcc 4.7 libstc ++?

Answer 1:

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

这不应该是必要的或者GCC或铛,并且将无法正常工作。 并非所有的libstdc ++头是该路径下,有其他地方的定义喜欢的东西一些必要的头_GLIBCXX_BEGIN_NAMESPACE_VERSION

它不会失败,因为GCC GCC已经知道如何找到另一头,所以它是多余明确地使用-I-L选项。 因为你只是告诉它如何找到一些它需要的头,但不告诉它如何找到剩下的它不锵工作。

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



Answer 2:

我使用铛 - 3.1 gcc4.6的libstdc ++在FreeBSD 9.0 / AMD64。 它适用于这些选项:

-I/usr/local/lib/gcc46/include/c++ \
-I/usr/local/lib/gcc46/include/c++/x86_64-portbld-freebsd9.0 \
-L/usr/local/lib/gcc46

我猜你的问题可以得到解决使用这些选项:

-I/opt/local/include/gcc47/c++ \
-I/opt/local/include/gcc47/c++/x86_64-apple-darwin11.3.0 \
-L/opt/local/lib/gcc47


Answer 3:

您可以使用特殊选项-gcc-toolchain ,这是由隐式设置--with-gcc-toolchain在编译时铿锵。 当你想使用其他GCC库这比重新编译铛更容易一点:)

像那样:

~/clang/trunk/bin/clang++ main.cc -gcc-toolchain ~/gcc/trunk -o main

或者,你的情况(我知道这是4岁:))这似乎是

clang++ main.cpp -o main -gcc-toolchain /opt/local

在“工具链”文件夹中应该包含“包括”和“LIB”文件夹。 这两种编译器和连接使用此选项。 小心: --gcc-toolchain不是一个有效的选项,使用一个破折号作为前缀(即使LLVM维基另有规定-我检查了它的铿锵3.8主干)。



文章来源: When enabling C++11 with stdlibc++ 4.7, clang error out, while gcc compiles fine