PlatformIO Community

*.c source file doesn't compile


#1

I write a program for Teensy 2.0 in ANSI C, but I can only compile it if the file extension is *.cpp or .ino. Having in mind that pure C is valid C++ syntax why I get compilation errors for almost every single line of code?

ini file:

[env:teensy20]
platform = teensy
framework = arduino
board = teensy20
build_flags = -D USB_MIDI

Am I missing something in the configuration of the project? By the way I have included the arduino library header #include <Arduino.h> on top of the program.


#2

Because Arduino is C++ project. You need to implement setup/loop functions. See https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/main.cpp

If you want to use pure C, then comment framework = arduino line. See native example for AVR https://github.com/platformio/platform-atmelavr/tree/develop/examples/native-blink