问题
I'm trying to compile VCMI under OS X 10.7 using clang++.
I configured project with CXX=clang++
because Apple's gcc didn't seem to recognize required -std=c++0x
flag.
I've added -stdlib=libc++
to CXXFLAGS
because without that clang wasn't even able to find #include <array>
.
Currently i've got: CXXFLAGS= -std=c++0x -stdlib=libc++ -Wall -Wextra -Wcast-align -Wpointer-arith -Wno-switch -Wno-sign-compare -Wno-unused-parameter -Wc++11-extensions
The problem is that I get following errors:
clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated
clang: warning: argument unused during compilation: '-ggdb'
StdInc.h:1:9: warning: #pragma once in main file
#pragma once
^
In file included from StdInc.h:3:
In file included from ./../Global.h:32:
In file included from /usr/bin/../lib/c++/v1/algorithm:594:
In file included from /usr/bin/../lib/c++/v1/memory:596:
/usr/bin/../lib/c++/v1/iterator:1696:1: error: 'inline' can only appear on functions
inline _LIBCPP_INLINE_VISIBILITY
^
/usr/bin/../lib/c++/v1/iterator:1698:1: error: variable 'begin' declared as a template
begin(_T (&__array)[_N])
^
/usr/bin/../lib/c++/v1/iterator:1698:12: error: use of undeclared identifier '__array'
begin(_T (&__array)[_N])
^
./../tchar_amigaos4.h:157:16: note: expanded from macro '_T'
#define _T(x) x
^
In file included from StdInc.h:3:
In file included from ./../Global.h:32:
In file included from /usr/bin/../lib/c++/v1/algorithm:594:
In file included from /usr/bin/../lib/c++/v1/memory:596:
/usr/bin/../lib/c++/v1/iterator:1698:25: error: expected ';' at end of declaration
begin(_T (&__array)[_N])
^
;
/usr/bin/../lib/c++/v1/iterator:1699:1: error: expected unqualified-id
{
^
1 warning and 5 errors generated.
I must admit that I've never saw anything like this. These are in libc++ sources! Does anybody know what may be the cause?
回答1:
Your issue is here:
./../tchar_amigaos4.h:157:16: note: expanded from macro '_T'
#define _T(x) x
Defining a macro named _T in your code, then including standard headers, is undefined behavior, strictly speaking.
IIRC, newer versions of libc++ avoid the use of the name _T in particular because people tend to screw this up, so you might want to try upgrading to the newest version of the command-line tools.
来源:https://stackoverflow.com/questions/11969908/c-error-inline-can-only-appear-on-functions