Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
140 views
in Technique[技术] by (71.8m points)

c++ - How can I use a C++11 to program the Arduino?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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),

  1. Locate the platform.txt file,
  • AVR architecture => {install path}hardwarearduinoavrplatform.txt
  • SAM architecture => {install path}hardwarearduinosamplatform.txt
  1. Inside that file, you can change any flag, for instance,
  • compiler.c.flags for changing the default compilation flags for C++ files.
  • compiler.cpp.flags for changing the default compilation flags for C++ files.
  1. You can also change any of the "recipes" or compile patters, at the corresponding section of the configuration file, under the title "AVR/SAM compile patterns".
  2. After making the changes, you must restart the Arduino IDE, at least on version 1.5.7.

For instance,

To enable support for C++11 (C++0x), tested on Arduino IDE versions 1.5.7 and 1.5.8, you will simply add the flag "-std=gnu++11" at the end of the line starting with compiler.cpp.flags=".

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...