I am making a library for a specific board for the Arduino IDE. The library works great and now I'm taking a step back to add OO. The Library is a mix of .c and .cpp files. I know in order to add classes I need only use .cpp.
This is the LED.h file.
https://gist.github.com/SaraJo/182220fda82cbe30255fe95f59d4a6b4
Here is the LED.cpp file.
https://gist.github.com/SaraJo/1b3d6967d7bc2ef2e70d79025b755eb9
The error I get is:
In file included from /Users/sarachipps/Library/Arduino15/packages/Jewelbots/hardware/nRF51822/1.0.0/cores/JWB_nRF51822/Arduino.h:54:0,
from /Users/sarachipps/Library/Arduino15/packages/Jewelbots/hardware/nRF51822/1.0.0/cores/JWB_nRF51822/ble-nrf51822-master/source/main.c:49:
/Users/sarachipps/Library/Arduino15/packages/Jewelbots/hardware/nRF51822/1.0.0/cores/JWB_nRF51822/LED.h:12:1: error: unknown type name 'class'
class LED {
^
/Users/sarachipps/Library/Arduino15/packages/Jewelbots/hardware/nRF51822/1.0.0/cores/JWB_nRF51822/LED.h:12:11: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
class LED {
^
exit status 1
Error compiling for board JWB nRF51822(V1.0 32KB).
I'm guessing that the Arduino is seeing the .cpp file as .c, is there a compiler flag I need to set? Thank you.
extern "C"
on both declaration (aka prototype) and definition (if it is necessary, i.e. if yourmain.cpp
declares anything that someone else calls (which it usually shouldn't). The main() function itself should not need it, the C++ compiler knows to do that implicitly. – Niko