Skip to main content
Arduino

Return to Answer

replaced http://arduino.stackexchange.com/ with https://arduino.stackexchange.com/
Source Link

What I want to know is "how do I write a program such that it is considered valid both by the Arduino IDE and g++.

See: How to avoid the quirks of the IDE sketch file pre-preprocessing.

Disregarding for the moment what the Makefile will look like, the simple answer to your question, as discussed in the above link, is to put everything into .cpp and .h tabs in the IDE, and leave the main "sketch" (.ino file) blank. That will still compile under the IDE, and will also therefore be normal C++.

Make sure you start your .cpp files with:

#include <Arduino.h>

If you use libraries (eg, SPI) you must include them in the main sketch file, which triggers the IDE to copy them into the temporary project build file. The Makefile won't care about that, as you will make sure your Makefile includes all the necessary library files.

Also see my answer here: Classes and objects: how many and which file types do I actually need to use them? Classes and objects: how many and which file types do I actually need to use them?

What I want to know is "how do I write a program such that it is considered valid both by the Arduino IDE and g++.

See: How to avoid the quirks of the IDE sketch file pre-preprocessing.

Disregarding for the moment what the Makefile will look like, the simple answer to your question, as discussed in the above link, is to put everything into .cpp and .h tabs in the IDE, and leave the main "sketch" (.ino file) blank. That will still compile under the IDE, and will also therefore be normal C++.

Make sure you start your .cpp files with:

#include <Arduino.h>

If you use libraries (eg, SPI) you must include them in the main sketch file, which triggers the IDE to copy them into the temporary project build file. The Makefile won't care about that, as you will make sure your Makefile includes all the necessary library files.

Also see my answer here: Classes and objects: how many and which file types do I actually need to use them?

What I want to know is "how do I write a program such that it is considered valid both by the Arduino IDE and g++.

See: How to avoid the quirks of the IDE sketch file pre-preprocessing.

Disregarding for the moment what the Makefile will look like, the simple answer to your question, as discussed in the above link, is to put everything into .cpp and .h tabs in the IDE, and leave the main "sketch" (.ino file) blank. That will still compile under the IDE, and will also therefore be normal C++.

Make sure you start your .cpp files with:

#include <Arduino.h>

If you use libraries (eg, SPI) you must include them in the main sketch file, which triggers the IDE to copy them into the temporary project build file. The Makefile won't care about that, as you will make sure your Makefile includes all the necessary library files.

Also see my answer here: Classes and objects: how many and which file types do I actually need to use them?

Source Link
Nick Gammon
  • 38.9k
  • 13
  • 69
  • 125

What I want to know is "how do I write a program such that it is considered valid both by the Arduino IDE and g++.

See: How to avoid the quirks of the IDE sketch file pre-preprocessing.

Disregarding for the moment what the Makefile will look like, the simple answer to your question, as discussed in the above link, is to put everything into .cpp and .h tabs in the IDE, and leave the main "sketch" (.ino file) blank. That will still compile under the IDE, and will also therefore be normal C++.

Make sure you start your .cpp files with:

#include <Arduino.h>

If you use libraries (eg, SPI) you must include them in the main sketch file, which triggers the IDE to copy them into the temporary project build file. The Makefile won't care about that, as you will make sure your Makefile includes all the necessary library files.

Also see my answer here: Classes and objects: how many and which file types do I actually need to use them?

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /