Go Down

Topic: Library referencing other libraries will not compile - SOLVED (Read 978 times) previous topic - next topic

marco_c

Dec 21, 2012, 08:04 am Last Edit: Dec 21, 2012, 09:34 pm by marco_c Reason: 1
I am creating a library (called MIDIFile) that implements a class that can be used to read a MIDI file from an SD card and stream it to a MIDI device. I am using the SDFat library to read the SD card, so this is referenced in the library.

When I try and compile a test program, I get definition errors for items that are defined in the SDFat library. It just seems like the compiler cannot find the header file and no matter what combinations I try (order of includes, bracket types, relative paths) they don't seem to make any difference.

MIDI_FileRead2.ino:1:19: warning: SDFat.h: No such file or directory

SDFile and my new library are in the Sketchbook/libraries folder. I am running windows and I have the IDE 1.0.3.

Clearly I am not adding stuff in the header files in the right order, so here are the start of the files with the include sequence, and the erroe message I get. I am sure someone will have solved this before...

Midifile.h - the library header file
Code: [Select]
#ifndef _MIDIFILE_H
#define _MIDIFILE_H

// Arduino MIDI File library
//
// A class which can read Standard MIDI files.
//

#include <Arduino.h>
#include <SdFat.h>

class MidiFile
{
 public:
   MidiFile(void);
   MidiFile(uint8_t ss);
   MidiFile(const char* aFile);
   MidiFile(uint8_t ss, const char* aFile);

   ~MidiFile(void);



MidiFile.cpp - library code file implementing the class
Code: [Select]
// Arduino MIDI File library
//
// A class which can read Standard MIDI files.
//

#include <string.h>
#include "MidiFile.h"



My test program
Code: [Select]
#include <SDFat.h>
#include <MidiFile.h>

/*
* SD chip select pin.  Common values are:
* Arduino Ethernet shield, pin 4.
*/
#define  SD_SELECT  4
#define  MIDI_FILE  "LOOPDEMO.MID"

MidiFile SMF(SD_SELECT, MIDI_FILE);

/*
void dumpBuffer(SdFile *f, int len)
{
 for (int i=0; i<len; i++)
 {
   uint8_t  c = f->read();
   
   if ((i!=0) && ((i%8) == 0)) Serial.println();
   Serial.print(' ');
   if (c<=0xf) Serial.print('0');
   Serial.print(c, HEX);
 }
}
*/
void DumpSMF(void)
{
 Serial.println(SMF.getFilename());
 Serial.print("File Version:\t");
 Serial.println(SMF.getFormat());
 Serial.print("Tracks:\t\t");
 Serial.println(SMF.getTrackCount());
 Serial.print("Speed:\t\t");
 Serial.println(SMF.getTicksPerQuarterNote());
}

void setup(void)
{
 Serial.begin(57600);
 Serial.println("[MIDI file reader]");
 
 SMF.load();
 DumpSMF();

 // close the file:
 SMF.close();
}

void loop(void)
{
}


Error messages (compiler verbose turned on):
Code: [Select]
F:\arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=103 -IF:\arduino\hardware\arduino\cores\arduino -IF:\arduino\hardware\arduino\variants\standard -IF:\Marco\Documents\Programming\Arduino\Sketchbook\libraries\MIDIFile C:\Users\Marco\AppData\Local\Temp\build6922185689476771770.tmp\MIDI_FileRead2.cpp -o C:\Users\Marco\AppData\Local\Temp\build6922185689476771770.tmp\MIDI_FileRead2.cpp.o
MIDI_FileRead2.ino:1:19: warning: SDFat.h: No such file or directory
In file included from MIDI_FileRead2.ino:2:
F:\Marco\Documents\Programming\Arduino\Sketchbook\libraries\MIDIFile/MidiFile.h:33:19: warning: SdFat.h: No such file or directory
In file included from MIDI_FileRead2.ino:2:
F:\Marco\Documents\Programming\Arduino\Sketchbook\libraries\MIDIFile/MidiFile.h:132: error: 'SdFat' does not name a type
F:\Marco\Documents\Programming\Arduino\Sketchbook\libraries\MIDIFile/MidiFile.h:133: error: 'SdFile' does not name a type
F:\Marco\Documents\Programming\Arduino\Sketchbook\libraries\MIDIFile/MidiFile.h:136: error: 'SdFile' has not been declared
F:\Marco\Documents\Programming\Arduino\Sketchbook\libraries\MIDIFile/MidiFile.h:137: error: 'SdFile' has not been declared
Arduino libraries http://arduinocode.codeplex.com<br />Parola for Arduino http://parola.codeplex.com

PaulS

This:
Quote
MIDIFile/MidiFile.h

Doesn't look good. The directory and class name should match, I think.

Quote
MIDI_FileRead2.ino:1:19: warning: SDFat.h: No such file or directory
In file included from MIDI_FileRead2.ino:2:
F:\Marco\Documents\Programming\Arduino\Sketchbook\libraries\MIDIFile/MidiFile.h:33:19: warning: SdFat.h: No such file or directory

There is, strange as it might seem, a difference between SDFat.h and SdFat.h.


marco_c

Just goes to show you can stare at code and not see the obvious things.

Thanks Paul, that was the problem. Once I made all the text case consistent that problem went away and now I have to deal with other issues...
Arduino libraries http://arduinocode.codeplex.com<br />Parola for Arduino http://parola.codeplex.com

MarkT


This:
Quote
MIDIFile/MidiFile.h

Doesn't look good. The directory and class name should match, I think.




No reason at all for file names to match class names - in fact if you look at the SPI library you'll see the
class is called SPIClass in SPI.h, its the singleton instance that's called SPI

[edit: of course its a useful convention, worth following!]
[ I won't respond to messages, use the forum please ]

Go Up