user47725: I'm have problem compiling a code.
ardutest.ino:

#include "mylib.h"
#include <SD.h>

void setup() {

}

void loop() {
  fn();
}

mylib.h:
#ifndef mylib_h
#define mylib_h

#include "Arduino.h"


void fn(File &_file);

#endif

mylib.c:
#include "mylib.h"

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

When checking code in Arduino IDE I have this error:
In file included from sketch/mylib.c:1:0:
mylib.h:7: error: expected ')' before '&' token
 void fn(File &_file);
          ^
mylib.c:3: error: expected ')' before '&' token
 void fn(File &_file)
          ^
Multiple libraries were found for "SD.h"
 Used: /home/mario/Arduino/libraries/SD
 Not used: /home/mario/Programs/arduino/libraries/SD
exit status 1
expected ')' before '&' token

But if I put SD.h in mylib.h (other files are the same):
#ifndef mylib_h
#define mylib_h

#include "Arduino.h"
#include <SD.h>

void fn(File &_file);

#endif

I have this error:
In file included from /home/user/Arduino/libraries/SD/src/utility/Sd2Card.h:26:0,
                 from /home/user/Arduino/libraries/SD/src/utility/SdFat.h:29,
                 from /home/user/Arduino/libraries/SD/src/SD.h:20,
                 from sketch/mylib.h:5,
                 from sketch/mylib.c:1:
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:423:14: error: unknown type name 'pin_map_t'
 static const pin_map_t digitalPinMap[] = {

              ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:447:69: error: 'pin_map_t' undeclared here (not in a function)
 static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t);

                                                                     ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h: In function 'getPinMode':
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:455:32: error: request for member 'ddr' in something not a structure or union
     return (*digitalPinMap[pin].ddr >> digitalPinMap[pin].bit) & 1;

                                ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:455:58: error: request for member 'bit' in something not a structure or union
     return (*digitalPinMap[pin].ddr >> digitalPinMap[pin].bit) & 1;

                                                          ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h: In function 'setPinMode':
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:464:26: error: request for member 'ddr' in something not a structure or union
       *digitalPinMap[pin].ddr |= 1 << digitalPinMap[pin].bit;

                          ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:464:57: error: request for member 'bit' in something not a structure or union
       *digitalPinMap[pin].ddr |= 1 << digitalPinMap[pin].bit;

                                                         ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:466:26: error: request for member 'ddr' in something not a structure or union
       *digitalPinMap[pin].ddr &= ~(1 << digitalPinMap[pin].bit);

                          ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:466:59: error: request for member 'bit' in something not a structure or union
       *digitalPinMap[pin].ddr &= ~(1 << digitalPinMap[pin].bit);

                                                           ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h: In function 'fastDigitalRead':
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:475:32: error: request for member 'pin' in something not a structure or union
     return (*digitalPinMap[pin].pin >> digitalPinMap[pin].bit) & 1;

                                ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:475:58: error: request for member 'bit' in something not a structure or union
     return (*digitalPinMap[pin].pin >> digitalPinMap[pin].bit) & 1;

                                                          ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h: In function 'fastDigitalWrite':
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:484:26: error: request for member 'port' in something not a structure or union
       *digitalPinMap[pin].port |= 1 << digitalPinMap[pin].bit;

                          ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:484:58: error: request for member 'bit' in something not a structure or union
       *digitalPinMap[pin].port |= 1 << digitalPinMap[pin].bit;

                                                          ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:486:26: error: request for member 'port' in something not a structure or union
       *digitalPinMap[pin].port &= ~(1 << digitalPinMap[pin].bit);

                          ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:486:60: error: request for member 'bit' in something not a structure or union
       *digitalPinMap[pin].port &= ~(1 << digitalPinMap[pin].bit);

                                                            ^
In file included from /home/user/Arduino/libraries/SD/src/utility/SdFat.h:29:0,
                 from /home/user/Arduino/libraries/SD/src/SD.h:20,
                 from sketch/mylib.h:5,
Multiple libraries were found for "SD.h"
 Used: /home/user/Arduino/libraries/SD
 Not used: /home/user/Programs/arduino/libraries/SD
                 from sketch/mylib.c:1:
/home/user/Arduino/libraries/SD/src/utility/Sd2Card.h: At top level:
/home/user/Arduino/libraries/SD/src/utility/Sd2Card.h:70:1: error: initializer element is not constant
 uint8_t const  SD_CHIP_SELECT_PIN = SS;

 ^
/home/user/Arduino/libraries/SD/src/utility/Sd2Card.h:79:1: error: initializer element is not constant
 uint8_t const  SPI_MOSI_PIN = MOSI;

 ^
/home/user/Arduino/libraries/SD/src/utility/Sd2Card.h:81:1: error: initializer element is not constant
 uint8_t const  SPI_MISO_PIN = MISO;

 ^
/home/user/Arduino/libraries/SD/src/utility/Sd2Card.h:83:1: error: initializer element is not constant
 uint8_t const  SPI_SCK_PIN = SCK;

 ^
/home/user/Arduino/libraries/SD/src/utility/Sd2Card.h:176:1: error: unknown type name 'class'
 class Sd2Card {

 ^
/home/user/Arduino/libraries/SD/src/utility/Sd2Card.h:176:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 class Sd2Card {

               ^
In file included from /home/user/Arduino/libraries/SD/src/utility/SdFat.h:30:0,
                 from /home/user/Arduino/libraries/SD/src/SD.h:20,
                 from sketch/mylib.h:5,
                 from sketch/mylib.c:1:
/home/user/Arduino/libraries/SD/src/utility/FatStructs.h:405:1: error: initializer element is not constant
 uint8_t const DIR_ATT_FILE_TYPE_MASK = (DIR_ATT_VOLUME_ID | DIR_ATT_DIRECTORY);

 ^
In file included from /home/user/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino/Print.h:27:0,
                 from /home/user/Arduino/libraries/SD/src/utility/SdFat.h:31,
                 from /home/user/Arduino/libraries/SD/src/SD.h:20,
                 from sketch/mylib.h:5,
                 from sketch/mylib.c:1:
/home/user/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino/Printable.h:25:1: error: unknown type name 'class'
 class Print;
 ^
/home/user/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino/Printable.h:33:1: error: unknown type name 'class'
 class Printable
 ^
/home/user/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino/Printable.h:34:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
In file included from /home/user/Arduino/libraries/SD/src/utility/SdFat.h:31:0,
                 from /home/user/Arduino/libraries/SD/src/SD.h:20,
                 from sketch/mylib.h:5,
                 from sketch/mylib.c:1:
/home/user/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino/Print.h:37:1: error: unknown type name 'class'
 class Print
 ^
/home/user/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino/Print.h:38:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
In file included from /home/user/Arduino/libraries/SD/src/SD.h:20:0,
                 from sketch/mylib.h:5,
                 from sketch/mylib.c:1:
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:39:1: error: unknown type name 'class'
 class SdVolume;

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:55:1: error: initializer element is not constant
 uint8_t const O_RDONLY = O_READ;

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:59:1: error: initializer element is not constant
 uint8_t const O_WRONLY = O_WRITE;

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:61:1: error: initializer element is not constant
 uint8_t const O_RDWR = (O_READ | O_WRITE);

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:63:1: error: initializer element is not constant
 uint8_t const O_ACCMODE = (O_READ | O_WRITE);

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:94:1: error: initializer element is not constant
 uint8_t const FAT_FILE_TYPE_MIN_DIR = FAT_FILE_TYPE_ROOT16;

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:137:1: error: unknown type name 'class'
 class SdFile : public Print {

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:137:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
 class SdFile : public Print {

              ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:431:1: error: unknown type name 'class'
 class SdVolume {

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:431:16: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 class SdVolume {

                ^
In file included from /home/user/Arduino/libraries/SD/src/SD.h:21:0,
                 from sketch/mylib.h:5,
                 from sketch/mylib.c:1:
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h: In function 'FreeRam':
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h:43:7: error: 'reinterpret_cast' undeclared (first use in this function)
   if (reinterpret_cast<int>(__brkval) == 0) {

       ^
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h:43:7: note: each undeclared identifier is reported only once for each function it appears in
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h:43:24: error: expected expression before 'int'
   if (reinterpret_cast<int>(__brkval) == 0) {

                        ^
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h:45:36: error: expected expression before 'int'
     free_memory = reinterpret_cast<int>(&free_memory)

                                    ^
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h:49:36: error: expected expression before 'int'
     free_memory = reinterpret_cast<int>(&free_memory)

                                    ^
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h: In function 'SerialPrint_P':
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h:62:52: error: 'Serial' undeclared (first use in this function)
   for (uint8_t c; (c = pgm_read_byte(str)); str++) Serial.write(c);

                                                    ^
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h: In function 'SerialPrintln_P':
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h:72:3: error: 'Serial' undeclared (first use in this function)
   Serial.println();

   ^
In file included from sketch/mylib.h:5:0,
                 from sketch/mylib.c:1:
/home/user/Arduino/libraries/SD/src/SD.h: At top level:
/home/user/Arduino/libraries/SD/src/SD.h:26:1: error: unknown type name 'namespace'
 namespace SDLib {
 ^
/home/user/Arduino/libraries/SD/src/SD.h:26:17: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 namespace SDLib {
                 ^
/home/user/Arduino/libraries/SD/src/SD.h:119:1: error: unknown type name 'using'
 using namespace SDLib;
 ^
/home/user/Arduino/libraries/SD/src/SD.h:119:17: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'SDLib'
 using namespace SDLib;
                 ^
/home/user/Arduino/libraries/SD/src/SD.h:123:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
 typedef SDLib::File    SDFile;
              ^
/home/user/Arduino/libraries/SD/src/SD.h:124:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
 typedef SDLib::SDClass SDFileSystemClass;
              ^
In file included from sketch/mylib.c:1:0:
mylib.h:7: error: expected ')' before '&' token
 void fn(File &_file);
              ^
mylib.c:3: error: expected ')' before '&' token
 void fn(File &_file)
              ^
exit status 1
expected ')' before '&' token

If I use SD.h function in mylib, I need this in mylib.h file. Why is it happens?
The first error is about passing object as function argument. I'm following sample I found in others forum, then I don't know why it isn't working.
[SOLVED]
I rename mylib.c to mylib.cpp and solved the problem.

user313: SD.h defines class File. Without that definition, 'File' is taken to be the name of an untyped argument (which will be assumed to be an int). Given that assumption, '&_file' is unexpected.

user55899: Firstly, there are different strategies for organizing header file structure. I don't know which one you follow. Within the popular approach that strives to keep all header files in self-sufficient state, mylib.h should include <SD.h> since mylib.h uses File type.
Secondly, when you actually included <SD.h> into mylib.h, you ran into a different problem. SD library is written as a C++ library. Its header files will not compile as C code. Meanwhile, you are trying to compile <SD.h> in C mode by indirectly including it into a mylib.c file, which is what causes the errors.

This library's header files contain many bizarre coding patterns that might create an impression as if someone was trying to make these headers compatible with C code (static const? static inline? Etc.), but this is an illusion. The code is exclusively C++, not C.

47725: <p>I'm have problem compiling a code.</p>

<p>ardutest.ino:
</p>

<pre class="lang-cpp prettyprint-override"><code>#include "mylib.h"
#include &lt;SD.h&gt;

void setup() {

}

void loop() {
  fn();
}
</code></pre>

<p>mylib.h:</p>

<pre class="lang-cpp prettyprint-override"><code>#ifndef mylib_h
#define mylib_h

#include "Arduino.h"


void fn(File &amp;_file);

#endif
</code></pre>

<p>mylib.c:</p>

<pre class="lang-cpp prettyprint-override"><code>#include "mylib.h"

void fn(File &amp;_file)
{
  _file = SD.open("LOG.TXT", FILE_WRITE);
  _file.println(42);
  _file.close();
}
</code></pre>

<p>When checking code in Arduino IDE I have this error:</p>

<pre class="lang-cpp prettyprint-override"><code>In file included from sketch/mylib.c:1:0:
mylib.h:7: error: expected ')' before '&amp;' token
 void fn(File &amp;_file);
          ^
mylib.c:3: error: expected ')' before '&amp;' token
 void fn(File &amp;_file)
          ^
Multiple libraries were found for "SD.h"
 Used: /home/mario/Arduino/libraries/SD
 Not used: /home/mario/Programs/arduino/libraries/SD
exit status 1
expected ')' before '&amp;' token
</code></pre>

<p>But if I put SD.h in mylib.h (other files are the same):</p>

<pre class="lang-cpp prettyprint-override"><code>#ifndef mylib_h
#define mylib_h

#include "Arduino.h"
#include &lt;SD.h&gt;

void fn(File &amp;_file);

#endif
</code></pre>

<p>I have this error:</p>

<pre class="lang-cpp prettyprint-override"><code>In file included from /home/user/Arduino/libraries/SD/src/utility/Sd2Card.h:26:0,
                 from /home/user/Arduino/libraries/SD/src/utility/SdFat.h:29,
                 from /home/user/Arduino/libraries/SD/src/SD.h:20,
                 from sketch/mylib.h:5,
                 from sketch/mylib.c:1:
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:423:14: error: unknown type name 'pin_map_t'
 static const pin_map_t digitalPinMap[] = {

              ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:447:69: error: 'pin_map_t' undeclared here (not in a function)
 static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t);

                                                                     ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h: In function 'getPinMode':
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:455:32: error: request for member 'ddr' in something not a structure or union
     return (*digitalPinMap[pin].ddr &gt;&gt; digitalPinMap[pin].bit) &amp; 1;

                                ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:455:58: error: request for member 'bit' in something not a structure or union
     return (*digitalPinMap[pin].ddr &gt;&gt; digitalPinMap[pin].bit) &amp; 1;

                                                          ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h: In function 'setPinMode':
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:464:26: error: request for member 'ddr' in something not a structure or union
       *digitalPinMap[pin].ddr |= 1 &lt;&lt; digitalPinMap[pin].bit;

                          ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:464:57: error: request for member 'bit' in something not a structure or union
       *digitalPinMap[pin].ddr |= 1 &lt;&lt; digitalPinMap[pin].bit;

                                                         ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:466:26: error: request for member 'ddr' in something not a structure or union
       *digitalPinMap[pin].ddr &amp;= ~(1 &lt;&lt; digitalPinMap[pin].bit);

                          ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:466:59: error: request for member 'bit' in something not a structure or union
       *digitalPinMap[pin].ddr &amp;= ~(1 &lt;&lt; digitalPinMap[pin].bit);

                                                           ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h: In function 'fastDigitalRead':
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:475:32: error: request for member 'pin' in something not a structure or union
     return (*digitalPinMap[pin].pin &gt;&gt; digitalPinMap[pin].bit) &amp; 1;

                                ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:475:58: error: request for member 'bit' in something not a structure or union
     return (*digitalPinMap[pin].pin &gt;&gt; digitalPinMap[pin].bit) &amp; 1;

                                                          ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h: In function 'fastDigitalWrite':
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:484:26: error: request for member 'port' in something not a structure or union
       *digitalPinMap[pin].port |= 1 &lt;&lt; digitalPinMap[pin].bit;

                          ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:484:58: error: request for member 'bit' in something not a structure or union
       *digitalPinMap[pin].port |= 1 &lt;&lt; digitalPinMap[pin].bit;

                                                          ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:486:26: error: request for member 'port' in something not a structure or union
       *digitalPinMap[pin].port &amp;= ~(1 &lt;&lt; digitalPinMap[pin].bit);

                          ^
/home/user/Arduino/libraries/SD/src/utility/Sd2PinMap.h:486:60: error: request for member 'bit' in something not a structure or union
       *digitalPinMap[pin].port &amp;= ~(1 &lt;&lt; digitalPinMap[pin].bit);

                                                            ^
In file included from /home/user/Arduino/libraries/SD/src/utility/SdFat.h:29:0,
                 from /home/user/Arduino/libraries/SD/src/SD.h:20,
                 from sketch/mylib.h:5,
Multiple libraries were found for "SD.h"
 Used: /home/user/Arduino/libraries/SD
 Not used: /home/user/Programs/arduino/libraries/SD
                 from sketch/mylib.c:1:
/home/user/Arduino/libraries/SD/src/utility/Sd2Card.h: At top level:
/home/user/Arduino/libraries/SD/src/utility/Sd2Card.h:70:1: error: initializer element is not constant
 uint8_t const  SD_CHIP_SELECT_PIN = SS;

 ^
/home/user/Arduino/libraries/SD/src/utility/Sd2Card.h:79:1: error: initializer element is not constant
 uint8_t const  SPI_MOSI_PIN = MOSI;

 ^
/home/user/Arduino/libraries/SD/src/utility/Sd2Card.h:81:1: error: initializer element is not constant
 uint8_t const  SPI_MISO_PIN = MISO;

 ^
/home/user/Arduino/libraries/SD/src/utility/Sd2Card.h:83:1: error: initializer element is not constant
 uint8_t const  SPI_SCK_PIN = SCK;

 ^
/home/user/Arduino/libraries/SD/src/utility/Sd2Card.h:176:1: error: unknown type name 'class'
 class Sd2Card {

 ^
/home/user/Arduino/libraries/SD/src/utility/Sd2Card.h:176:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 class Sd2Card {

               ^
In file included from /home/user/Arduino/libraries/SD/src/utility/SdFat.h:30:0,
                 from /home/user/Arduino/libraries/SD/src/SD.h:20,
                 from sketch/mylib.h:5,
                 from sketch/mylib.c:1:
/home/user/Arduino/libraries/SD/src/utility/FatStructs.h:405:1: error: initializer element is not constant
 uint8_t const DIR_ATT_FILE_TYPE_MASK = (DIR_ATT_VOLUME_ID | DIR_ATT_DIRECTORY);

 ^
In file included from /home/user/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino/Print.h:27:0,
                 from /home/user/Arduino/libraries/SD/src/utility/SdFat.h:31,
                 from /home/user/Arduino/libraries/SD/src/SD.h:20,
                 from sketch/mylib.h:5,
                 from sketch/mylib.c:1:
/home/user/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino/Printable.h:25:1: error: unknown type name 'class'
 class Print;
 ^
/home/user/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino/Printable.h:33:1: error: unknown type name 'class'
 class Printable
 ^
/home/user/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino/Printable.h:34:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
In file included from /home/user/Arduino/libraries/SD/src/utility/SdFat.h:31:0,
                 from /home/user/Arduino/libraries/SD/src/SD.h:20,
                 from sketch/mylib.h:5,
                 from sketch/mylib.c:1:
/home/user/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino/Print.h:37:1: error: unknown type name 'class'
 class Print
 ^
/home/user/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino/Print.h:38:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
In file included from /home/user/Arduino/libraries/SD/src/SD.h:20:0,
                 from sketch/mylib.h:5,
                 from sketch/mylib.c:1:
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:39:1: error: unknown type name 'class'
 class SdVolume;

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:55:1: error: initializer element is not constant
 uint8_t const O_RDONLY = O_READ;

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:59:1: error: initializer element is not constant
 uint8_t const O_WRONLY = O_WRITE;

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:61:1: error: initializer element is not constant
 uint8_t const O_RDWR = (O_READ | O_WRITE);

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:63:1: error: initializer element is not constant
 uint8_t const O_ACCMODE = (O_READ | O_WRITE);

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:94:1: error: initializer element is not constant
 uint8_t const FAT_FILE_TYPE_MIN_DIR = FAT_FILE_TYPE_ROOT16;

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:137:1: error: unknown type name 'class'
 class SdFile : public Print {

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:137:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
 class SdFile : public Print {

              ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:431:1: error: unknown type name 'class'
 class SdVolume {

 ^
/home/user/Arduino/libraries/SD/src/utility/SdFat.h:431:16: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 class SdVolume {

                ^
In file included from /home/user/Arduino/libraries/SD/src/SD.h:21:0,
                 from sketch/mylib.h:5,
                 from sketch/mylib.c:1:
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h: In function 'FreeRam':
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h:43:7: error: 'reinterpret_cast' undeclared (first use in this function)
   if (reinterpret_cast&lt;int&gt;(__brkval) == 0) {

       ^
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h:43:7: note: each undeclared identifier is reported only once for each function it appears in
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h:43:24: error: expected expression before 'int'
   if (reinterpret_cast&lt;int&gt;(__brkval) == 0) {

                        ^
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h:45:36: error: expected expression before 'int'
     free_memory = reinterpret_cast&lt;int&gt;(&amp;free_memory)

                                    ^
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h:49:36: error: expected expression before 'int'
     free_memory = reinterpret_cast&lt;int&gt;(&amp;free_memory)

                                    ^
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h: In function 'SerialPrint_P':
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h:62:52: error: 'Serial' undeclared (first use in this function)
   for (uint8_t c; (c = pgm_read_byte(str)); str++) Serial.write(c);

                                                    ^
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h: In function 'SerialPrintln_P':
/home/user/Arduino/libraries/SD/src/utility/SdFatUtil.h:72:3: error: 'Serial' undeclared (first use in this function)
   Serial.println();

   ^
In file included from sketch/mylib.h:5:0,
                 from sketch/mylib.c:1:
/home/user/Arduino/libraries/SD/src/SD.h: At top level:
/home/user/Arduino/libraries/SD/src/SD.h:26:1: error: unknown type name 'namespace'
 namespace SDLib {
 ^
/home/user/Arduino/libraries/SD/src/SD.h:26:17: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 namespace SDLib {
                 ^
/home/user/Arduino/libraries/SD/src/SD.h:119:1: error: unknown type name 'using'
 using namespace SDLib;
 ^
/home/user/Arduino/libraries/SD/src/SD.h:119:17: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'SDLib'
 using namespace SDLib;
                 ^
/home/user/Arduino/libraries/SD/src/SD.h:123:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
 typedef SDLib::File    SDFile;
              ^
/home/user/Arduino/libraries/SD/src/SD.h:124:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
 typedef SDLib::SDClass SDFileSystemClass;
              ^
In file included from sketch/mylib.c:1:0:
mylib.h:7: error: expected ')' before '&amp;' token
 void fn(File &amp;_file);
              ^
mylib.c:3: error: expected ')' before '&amp;' token
 void fn(File &amp;_file)
              ^
exit status 1
expected ')' before '&amp;' token
</code></pre>

<p>If I use SD.h function in mylib, I need this in mylib.h file. Why is it happens?</p>

<p>The first error is about passing object as function argument. I'm following sample I found in others forum, then I don't know why it isn't working.</p>

<p>[SOLVED]
I rename mylib.c to mylib.cpp and solved the problem.</p>
 313: <p>SD.h defines <code>class File</code>. Without that definition, 'File' is taken to be the name of an untyped argument (which will be assumed to be an int). Given that assumption, '&amp;_file' is unexpected.</p>
 55899: <p>Firstly, there are different strategies for organizing header file structure. I don't know which one you follow. Within the popular approach that strives to keep all header files in self-sufficient state, <code>mylib.h</code> should include <code>&lt;SD.h&gt;</code> since <code>mylib.h</code> uses <code>File</code> type.</p>

<p>Secondly, when you actually included <code>&lt;SD.h&gt;</code> into <code>mylib.h</code>, you ran into a different problem. SD library is written as a C++ library. Its header files will not compile as C code. Meanwhile, you are trying to compile <code>&lt;SD.h&gt;</code> in C mode by indirectly including it into a <code>mylib.c</code> file, which is what causes the errors.</p>

<hr>

<p>This library's header files contain many bizarre coding patterns that might create an impression <em>as if</em> someone was trying to make these headers compatible with C code (<code>static const</code>? <code>static inline</code>? Etc.), but this is an illusion. The code is exclusively C++, not C.</p>
