Error compiling when include and function with object as argument

Hi!

I have a problem building below sample code. Different error occurs when include lib in main.cpp or mylib.h.

main.cpp

#include <Arduino.h>

#include <Wire.h>
#include <SPI.h>
#include <SD.h>

#include "mylib.h"

File file;

void setup() {

}

void loop() {
    fn(file);
}

mylib.h:

#include <Arduino.h>

void fn(File &_file);

mylib.c:

#include "mylib.h"

void fn(File &_file)
{
  _file = SD.open("LOG.TXT", FILE_WRITE);
  _file.println(42);
  _file.close();
}

When I build it, I have this errors:

In file included from lib/mylib/mylib.c:1:0:
lib/mylib/mylib.h:4:14: error: expected ')' before '&' token
void fn(File &_file);
^
lib/mylib/mylib.c:3:14: error: expected ')' before '&' token
void fn(File &_file)
^
*** [.pioenvs/uno/libd4c/mylib/mylib.c.o] Error 1

When I’m editing mylib.h, PlatformIO Linter inform me that, for instance, ‘File’ was not declared in scope. Then I add lib in mylib.h as:

mylib.h

#include <Arduino.h>

#include <Wire.h>
#include <SPI.h>
#include <SD.h>

void fn(File &_file);

Other files still the same.

When I build it again I have a lot error compiling internal Arduino libraries. Next a part of error (I can’t copy all 1000 lines of error in PlatformIO):

In file included from /home/user/.platformio/packages/framework-arduinoavr/cores/arduino/Print.h:27:0,
from /home/user/.platformio/packages/framework-arduinoavr/cores/arduino/Stream.h:26,
from /home/user/.platformio/packages/framework-arduinoavr/libraries/__cores__/arduino/Wire/src/Wire.h:26,
from lib/mylib/mylib.h:3,
from lib/mylib/mylib.c:1:
/home/user/.platformio/packages/framework-arduinoavr/cores/arduino/Printable.h:25:1: error: unknown type name 'class'
class Print;
^
/home/user/.platformio/packages/framework-arduinoavr/cores/arduino/Printable.h:33:1: error: unknown type name 'class'
class Printable
^
/home/user/.platformio/packages/framework-arduinoavr/cores/arduino/Printable.h:34:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
...

Why I have this differnt errors when add libs in mylib.h? That is the right way to pass object to a function? I follow an exemple I found in Arduino forum.

I’m using PlatformIO 1.0.2 Core 3.6.0a11 and Atom 1.29.0 x64.

All the best!

Mario

Just rename C => CPP. Extension.