8
votes

I am writing an portable application which uses C++11 features like std::atomic, std::threads, etc. How do I verify that my ARM GCC cross compiler toolchain supports the C++11 standard?

I tried using arm-none-linux-gnueabi-g++ -v and arm-none-linux-gnueabi-g++ --version but it returned error when using -std=c++11

EDIT # arm-linux-gnueabi-g++ -std=c++11 dum.cpp

cc1plus: error: unrecognized command line option '-std=c++11'

Target: arm-linux-gnueabi

gcc version 4.6.2

1
Sorry, my crystal ball is absolutely silent about the error you got. Care to share it? ;)syam
@syam Added the compiler error message!manav m-n
Yeah well GCC 4.6 didn't support the -std=c++11 flag since it was released before the C++11 standard was published, but -std=c++0x was supported. However you might find that GCC 4.6 doesn't fit your requirements. Your best bet would be to determine the minimal GCC version you need (with respect to the features you use) and enforce it in your configure.ac script. Note however that only GCC 4.8 has full C++11 core language support, but it doesn't even have full library support yet.syam

1 Answers

6
votes

Look at cxx0x support matrix. ARM Linux supports most features in a standard way. It is possible that a particular machine may not support a feature. Ie, the gcc version, linux version and glibc version and CPU type could all come into play.

Test the define __VERSION__ to see if the compiler can support it. Very, very old Linux versions may have no way to support this with some CPU types; ARMv5 and older. Newer ARM CPUs have some bus locking instructions and can support this with out any or little OS support.

echo | g++ -dM -E - | grep -i atomic

Should give a list of defines. If you compile with -march=armv7, you will have the most luck. However, with more recent Linux versions (and compiler/glibc targeting this version), even the -march=armv5 will work on non-SMP systems. I don't think an ARMv5 SMP system can exist.

As you can see there are many working parts and it is possible that some features may only be known to work at run time. It is probably impossible to provide a list; you need a gcc version with at least the support matrix for it to be possible that the feature works.

For example, with the same compiler but only -march=armv4 versus -march=armv6,

armv4

#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 1
#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 1
#define __GCC_ATOMIC_LONG_LOCK_FREE 1
#define __GCC_ATOMIC_POINTER_LOCK_FREE 1
#define __GCC_ATOMIC_INT_LOCK_FREE 1

armv6

#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
#define __GCC_ATOMIC_INT_LOCK_FREE 2
#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
#define __GCC_ATOMIC_LONG_LOCK_FREE 2

Most modern smart phones with have armv7 or better.