当使用 stdlibc++ 4.7 启用 C++11 时,clang 错误,而 gcc 编译正常
When enabling C++11 with stdlibc++ 4.7, clang error out, while gcc compiles fine
我一直在尝试让 C++11 工作,在浏览不同的网站和问答后,我仍然遇到问题。我想将 clang 与 libstdc++ 一起使用。在 clang 状态中指示它受修补程序 - http://clang.llvm.org/libstdc++4.7-clang11.patch 的支持。我从macports下载了gcc4.7,并在gcc4.7的标题中进行了相应的更改
我不使用 libc++ 的原因是因为 libc++和 libstdc++ 之间的 ABI 兼容性,由以下线程指示:为什么不能在 c++0x 模式下与 libc++ 链接此 boost::p rogram_options 示例?
好的,完成所有操作后,我使用以下代码测试了我的设置:
#include <mutex>
#include <thread>
int main ( ) {
std::mutex myMutext;
return 0;
}
我希望包含应该在 c++11 下工作。
所以这是我编译它的方式:与海湾合作委员会
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.
我正在使用 clang 版本:
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++ 的 clang 问题?
你为什么说-I/opt/local/include/gcc47/c++
?
这对于 GCC 或 Clang 来说都不是必需的,并且不起作用。 并非所有 libstdc++ 标头都在该路径下,其他地方有一些重要的标头定义了诸如_GLIBCXX_BEGIN_NAMESPACE_VERSION
GCC 不会失败,因为 GCC 已经知道如何找到其他标头,因此显式使用 -I
和 -L
选项是多余的。 它不适用于 Clang,因为您只告诉它如何找到它需要的一些标头,而不是告诉它如何找到其余的标头。
停止尝试覆盖编译器的标准库路径,让它使用它已经知道的内置路径。
我在 FreeBSD 9.0/AMD64 上使用 clang-3.1 和 gcc4.6 libstdc++。它适用于以下选项:
-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
您可以使用特殊选项 -gcc-toolchain
,这是在编译 clang 时由 --with-gcc-toolchain
隐式设置的。当您想使用另一个 GCC 库时,这比重新编译 clang 容易一些:)
诸如此类:
~/clang/trunk/bin/clang++ main.cc -gcc-toolchain ~/gcc/trunk -o main
或者,在您的情况下(我知道它是 4 岁:))它似乎是
clang++ main.cpp -o main -gcc-toolchain /opt/local
"工具链"文件夹应包含"包含"和"库"文件夹。编译器和链接器都使用此选项。请注意:--gcc-toolchain
不是一个有效的选项,请使用一个破折号作为前缀(即使 llvm wiki 另有说明 - 我在 clang 3.8 主干上检查了它)。
- <filesystem> 在 clang 6 和 10 上 #include 错误
- Android NDK clang 编译器错误在 Windows 上显示'No such file or directory'
- 错误:使用 clang 没有可行的重载,使用 GCC 编译
- Clang 8 带有静态 constexpr 和数组的链接器错误 - 错误是什么以及如何解决它?
- 如何使用 CLANG 禁用格式安全错误?
- 通过自制软件(macOS)安装的clang++:编译错误
- 获取 clang++:错误:在编译文件系统库的代码时
- C++20 个模块在 clang (Windows):在最简单的示例中键入信息错误
- 与clang++一起使用的VS代码在构建良好的C++文件中显示错误
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 在Visual Studio中使用括号时编译错误,但在G ++ / CLang ++中传递
- 为什么 Clang 在命名空间'std'中没有名为 'copy' 的成员给出错误
- "Make"失败并出现 Clang 错误 - 如何从 Clang 获得错误?
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- "删除"在 g++ 中抛出错误,同时在 clang 中完美编译
- Clang 无法检测到初始化并给出错误
- 在折叠表达式中使用 lambda 时"Uninitialized captured reference"错误 - clang vs gcc
- C++ std::this_thread::sleep_for编译器错误 (CLANG)
- 链接器错误- clang++