Neg*_*ero 9 c++ macos gcc clang c++11
我一直在尝试让C++ 11工作,在浏览了不同的网站和Q/A之后,我仍然遇到了麻烦.我想和libstdc ++一起使用clang.它在clang状态中表示它受补丁支持 - http://clang.llvm.org/libstdc++4.7-clang11.patch.我从macports下载gcc4.7并在gcc4.7的头文件中做了相应的更改
我不使用libc ++的原因是因为libc ++和libstdc ++之间的ABI兼容性,由这个线程表示:为什么不能用c ++ 0x模式中的libc ++来链接这个boost :: program_options示例?
好的,一切都完成后,我使用以下代码测试了我的设置:
#include <mutex>
#include <thread>
int main ( ) {
std::mutex myMutext;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我期待include应该在c ++ 11下工作.
所以这就是我用GCC编译它的方法
g++ -std=c++11 -I/opt/local/include/gcc47/c++ -L/opt/local/lib/gcc47 main.cpp -o main
Run Code Online (Sandbox Code Playgroud)
编译成功
与Clang
clang++ -std=c++11 -I/opt/local/include/gcc47/c++ -L/opt/local/lib/gcc47 main.cpp -o main
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
@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.
Run Code Online (Sandbox Code Playgroud)
我正在使用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
Run Code Online (Sandbox Code Playgroud)
难道我做错了什么?或者这是最新的gcc 4.7 libstc ++的铿锵问题?
你为什么这么说-I/opt/local/include/gcc47/c++?
对于GCC或Clang来说,这不应该是必要的,并且不会起作用.并非所有libstdc ++标头都在该路径下,其他地方有一些基本标头可以定义类似的内容_GLIBCXX_BEGIN_NAMESPACE_VERSION
它不会因GCC而失败,因为GCC已经知道如何查找其他标头,因此显式使用-I和-L选项是多余的.它不适用于Clang,因为你只是告诉它如何找到它需要的一些头文件,但没有告诉它如何找到其余的头文件.
停止尝试覆盖编译器的标准库路径,让它使用它已经知道的内置路径.
小智 7
我在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
Run Code Online (Sandbox Code Playgroud)
我想你的问题可能会被解决使用这些选项:
-I/opt/local/include/gcc47/c++ \
-I/opt/local/include/gcc47/c++/x86_64-apple-darwin11.3.0 \
-L/opt/local/lib/gcc47
Run Code Online (Sandbox Code Playgroud)