When turning on C ++ 11 with stdlibC ++ 4.7, clang error out, while gcc compiles fine

I'm trying to get C ++ 11 to work by browsing different sites and Q / A, I'm still having problems. I want to use clang with libstdc ++. The status of clang indicates that it supports the patch - http://clang.llvm.org/libstdc++4.7-clang11.patch . I download gcc4.7 from macports and make the appropriate header changes for gcc4.7

The reason why I do not use lib ++ is because ABI compatibility between lib ++ and libstd ++ is indicated in this thread: Why can not communicate with lib ++ in C ++ 0x mode this example boost: : program_options?

OK, after everything is done, I checked my installation with the following code:

#include <mutex> #include <thread> int main ( ) { std::mutex myMutext; return 0; } 

I expect include to 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 get 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 it a clang problem with the latest gcc 4.7 libstc ++?

+8
c ++ gcc c ++ 11 clang macos
source share
3 answers

Why do you say -I/opt/local/include/gcc47/c++ ?

This is not necessary for GCC or Clang and will not work. Not all libstdC ++ headers are under this path, there are some basic headers elsewhere that define things like _GLIBCXX_BEGIN_NAMESPACE_VERSION

This will not work with GCC, because GCC already knows how to find other headers, so it is redundant to use the -I and -L options. He does not work with Clang because you only tell him how to find some of the headings that he needs, but do not tell how to find the rest.

Stop trying to redefine the paths of the standard compiler library, let it use the built-in paths that it already knows about.

+8
source share

I am using clang-3.1 with gcc4.6 libstdc ++ on FreeBSD 9.0 / AMD64. It works with these parameters:

 -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 think your problem can be solved for using these parameters:

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

You can use the special option -gcc-toolchain , which is implicitly set to --with-gcc-toolchain when compiling clang. This is a little easier than recompiling clang if you want to use other GCC libraries :)

Like:

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

Or, in your case (I know it's 4 years :)), it seems

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

The toolchain folder should contain the include and lib folders. This compiler and linker use this parameter. Be careful: --gcc-toolchain not a valid parameter, use one dash as a prefix (even if the llvm wiki indicates otherwise - I checked its clang 3.8 trunk).

0
source share

All Articles