How can I use c++11
when programming the Arduino? I would be fine using either the Arduino IDE or another environment. I am most interested in the core language improvements, not things that require standard library changes.
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- 使用Webstorm打开刚下载的jquery为什么会有报错
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
Arduino IDE 1.6.6 and newer have C++11 enabled by default (they have the compiler flag "-std=gnu++11" set in the platform.txt file).
Please, note, that there is no easy way to specify additional flags from Arduino IDE or use other IDE (Eclipse, Code Blocks, etc) or command line.
As a hack, you can use a small proxy program (should be cross-platform):
You're done!
Example avr-g++.ini:
Hope, that helps!
Firstly, only
gcc
4.7 and above (and thereforeavr-gcc
4.7 and above) supportC++11
. So, check the versions installed with :If
avr-gcc
is 4.7 or higher, then you may be able to useC++11
.The Arduino IDE does not support custom compiler flags. This has been requested but has not yet been implemented.
So, you are left with having to use other environments or to compile your program directly from the command line.
In case, of compiling directly from the command line using
avr-gcc
, you simply need to add an extra compiler flag for enabling C++11 support.For specific development environments, most would support editing of the compiler flags from the build options within the IDE. The above mentioned flag needs to be added to the list of flags for each environment.
C++0x
was the name of working draft of theC++11
standard.C++0x
support is availablegcc
4.3 onwards. However, this is strictly experimental support so you cannot realiably expectC++11
features to be present. Here is the complete list of features available with the corresponding version ofgcc
. The availability of features inavr-gcc
will be the same as whats available in the correspondinggcc
version.The compiler flag for
C++0x
is :I use Ino and this worked:
ino build -cppflags="-std=c++0x"
This generated a hex file at least 15k in size (that's with optimizations turned on), compared to about 5k for the standard build, which is a consideration for a poor little Atmega328. Might be okay for one of the microcontrollers with a lot more program space.
As of version 1.6.6, the Arduino IDE enables c++11 by default.
For older versions, read on:
It is very easy to change the flags for any element of the toolchain, including the assembler, compiler, linker or archiver.
Tested on the Arduino IDE version 1.5.7 (released on July 2014),
For instance,
It is expected that C++11 is enabled by default in the near future on the Arduino IDE. However, as of version 1.5.8 (Oct 2014) it is still not the case.