SdFat Linking Issues

Hello All,

I am fairly new to programming the Uno and need help with getting SdFat to link. I am using IDE 1.0.6 on a Debian Wheezy box. I followed the instructions at http://arduino.cc/en/Guide/Libraries I downloaded SdFat.zip and installed it through 1.0.6->Sketch->Import Library... SdFat was installed in my sketchbook/libraries/SdFat directory and the SdFat library appears in the Sketch->Import Library menu.

I see ~/sketchbook/libraries/SdFat when I echo $LD_LIBRARY_PATH

However, I can not get any of my sketches to link to the SdFar libraries. I can link to the SD libraries fine.

Any ideas?

Thanks, Murrah Boswell

What do you mean? What message do you get? What sketch? What error message?

Thank you for your response, sorry to take so long to get back to you response.

Listing of example sketch SdFatRewrite:

/*

  • Rewrite Example
  • This sketch shows how to rewrite part of a line in the middle
  • of the file created by the SdFatAppend.pde example.
  • Check around line 30 of pass 50 of APPEND.TXT after running this sketch.
    */
    #include <SdFat.h>
    #include <SdFatUtil.h> // use functions to print strings from flash memory

Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))
void error_P(const char *str)
{
PgmPrint("error: ");
SerialPrintln_P(str);
if (card.errorCode()) {
PgmPrint("SD error: ");
Serial.print(card.errorCode(), HEX);
Serial.print(’,’);
Serial.println(card.errorData(), HEX);
}
while(1);
}

void setup(void)
{
Serial.begin(9600);
Serial.println();
PgmPrintln(“Type any character to start”);
while (!Serial.available());

// initialize the SD card
if (!card.init()) error(“card.init”);

// initialize a FAT volume
if (!volume.init(card)) error(“volume.init”);

// open the root directory
if (!root.openRoot(volume)) error(“openRoot”);

char name = “APPEND.TXT”;
// open for read and write
if (!file.open(root, name, O_RDWR)) {
PgmPrint(“Can’t open “);
Serial.println(name);
PgmPrintln(“Run the append example to create the file.”);
error(“file.open”);
}
// seek to middle of file
if (!file.seekSet(file.fileSize()/2)) error(“file.seekSet”);
// find end of line
int16_t c;
while ((c = file.read()) > 0 && c != ‘\n’);
if (c < 0) error(“file.read”);
// clear write error flag
file.writeError = false;
// rewrite the begining of the line at the current position
file.write(“rewrite”);
if (file.writeError) error(“file.write”);
if (!file.close()) error(“file.close”);
Serial.print(name);
PgmPrintln(” rewrite done.”);
}

void loop(void) {}


errors:

Arduino: 1.0.6 (Linux), Board: “Arduino Mega 2560 or Mega ADK”
/home/otrcomm/downloads/arduino-ide/arduino-1.0.6/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -I/home/otrcomm/downloads/arduino-ide/arduino-1.0.6/hardware/arduino/cores/arduino -I/home/otrcomm/downloads/arduino-ide/arduino-1.0.6/hardware/arduino/variants/mega -I/home/otrcomm/sketchbook/libraries/SdFat /tmp/build6496159611916882408.tmp/SdFatRewrite.cpp -o /tmp/build6496159611916882408.tmp/SdFatRewrite.cpp.o
In file included from /home/otrcomm/sketchbook/libraries/SdFat/SdFat.h:30,
from SdFatRewrite.pde:9:
/home/otrcomm/sketchbook/libraries/SdFat/Sd2Card.h:39:22: warning: extra tokens at end of #ifdef directive
In file included from SdFatRewrite.pde:10:
/home/otrcomm/sketchbook/libraries/SdFat/SdFatUtil.h:27:22: warning: WProgram.h: No such file or directory
In file included from SdFatRewrite.pde:9:
/home/otrcomm/sketchbook/libraries/SdFat/SdFat.h:294: error: conflicting return type specified for ‘virtual void SdFile::write(uint8_t)’
/home/otrcomm/downloads/arduino-ide/arduino-1.0.6/hardware/arduino/cores/arduino/Print.h:48: error: overriding ‘virtual size_t Print::write(uint8_t)’
In file included from SdFatRewrite.pde:10:
/home/otrcomm/sketchbook/libraries/SdFat/SdFatUtil.h: In function ‘void SerialPrint_P(const prog_char*)’:
/home/otrcomm/sketchbook/libraries/SdFat/SdFatUtil.h:60: error: ‘Serial’ was not declared in this scope
/home/otrcomm/sketchbook/libraries/SdFat/SdFatUtil.h: In function ‘void SerialPrintln_P(const prog_char*)’:
/home/otrcomm/sketchbook/libraries/SdFat/SdFatUtil.h:71: error: ‘Serial’ was not declared in this scope
SdFatRewrite.pde: In function ‘void error_P(const char*)’:
SdFatRewrite.pde:21: warning: only initialized variables can be placed into program memory area
SdFatRewrite.pde:24: warning: only initialized variables can be placed into program memory area
SdFatRewrite.pde: In function ‘void setup()’:
SdFatRewrite.pde:36: warning: only initialized variables can be placed into program memory area
SdFatRewrite.pde:40: warning: only initialized variables can be placed into program memory area
SdFatRewrite.pde:43: warning: only initialized variables can be placed into program memory area
SdFatRewrite.pde:46: warning: only initialized variables can be placed into program memory area
SdFatRewrite.pde:51: warning: only initialized variables can be placed into program memory area
SdFatRewrite.pde:53: warning: only initialized variables can be placed into program memory area
SdFatRewrite.pde:54: warning: only initialized variables can be placed into program memory area
SdFatRewrite.pde:57: warning: only initialized variables can be placed into program memory area
SdFatRewrite.pde:61: warning: only initialized variables can be placed into program memory area
SdFatRewrite.pde:66: warning: only initialized variables can be placed into program memory area
SdFatRewrite.pde:67: warning: only initialized variables can be placed into program memory area
SdFatRewrite.pde:69: warning: only initialized variables can be placed into program memory area
/home/otrcomm/sketchbook/libraries/SdFat/SdFatUtil.h: At global scope:
/home/otrcomm/sketchbook/libraries/SdFat/SdFatUtil.h:37: warning: ‘int FreeRam()’ defined but not used

I can not compile any of the examples provided the SdFat library.

Thanks in advance for your help!

What version of SdFat are you using?

SdFat/SdFatUtil.h:27:22: warning: WProgram.h: No such file or directory
In file included from SdFatRewrite.pde:9:

This is from a really old library that can not be used with Arduino 1.0 or newer

Try this version of SdFat.

Hello, thanks for your response.

Using the version of SdFat that you provided the link to at GitHub and running the provided bench example sketch:

/*

  • This sketch is a simple binary write/read benchmark.
    */
    #include <SdFat.h>
    #include <SdFatUtil.h>

// SD chip select pin
const uint8_t chipSelect = SS;

// Size of read/write.
const size_t BUF_SIZE = 512;

// File size in MB where MB = 1,000,000 bytes.
const uint32_t FILE_SIZE_MB = 5;

// Write pass count.
const uint8_t WRITE_COUNT = 10;

// Read pass count.
const uint8_t READ_COUNT = 5;
//==============================================================================
// End of configuration constants.
//------------------------------------------------------------------------------
// File size in bytes.
const uint32_t FILE_SIZE = 1000000UL*FILE_SIZE_MB;

uint8_t buf[BUF_SIZE];

// file system
SdFat sd;

// test file
SdFile file;

// Serial output stream
ArduinoOutStream cout(Serial);
//------------------------------------------------------------------------------
// store error strings in flash to save RAM
#define error(s) sd.errorHalt_P(PSTR(s))
//------------------------------------------------------------------------------
void cidDmp() {
cid_t cid;
if (!sd.card()->readCID(&cid)) {
error(“readCID failed”);
}
cout << pstr("\nManufacturer ID: ");
cout << hex << int(cid.mid) << dec << endl;
cout << pstr("OEM ID: ") << cid.oid[0] << cid.oid[1] << endl;
cout << pstr("Product: ");
for (uint8_t i = 0; i < 5; i++) {
cout << cid.pnm*;*

  • }*

  • cout << pstr("\nVersion: ");*

  • cout << int(cid.prv_n) << ‘.’ << int(cid.prv_m) << endl;*

  • cout << pstr("Serial number: ") << hex << cid.psn << dec << endl;*

  • cout << pstr("Manufacturing date: ");*

  • cout << int(cid.mdt_month) << ‘/’;*
    cout << (2000 + cid.mdt_year_low + 10 * cid.mdt_year_high) << endl;

  • cout << endl;*
    }
    //------------------------------------------------------------------------------
    void setup() {

  • Serial.begin(9600);*

  • while (!Serial){} // wait for Leonardo*

  • cout << pstr("\nUse a freshly formatted SD for best performance.\n");*

  • // use uppercase in hex and use 0X base prefix*

  • cout << uppercase << showbase << endl;*
    }
    //------------------------------------------------------------------------------
    void loop() {

  • float s;*

  • uint32_t t;*

  • uint32_t maxLatency;*

  • uint32_t minLatency;*

  • uint32_t totalLatency;*

  • // discard any input*

  • while (Serial.read() >= 0) {}*

  • // pstr stores strings in flash to save RAM*

  • cout << pstr(“Type any character to start\n”);*

  • while (Serial.read() <= 0) {}*

  • delay(400); // catch Due reset problem*

  • cout << pstr("Free RAM: ") << FreeRam() << endl;*

  • // initialize the SD card at SPI_FULL_SPEED for best performance.*

  • // try SPI_HALF_SPEED if bus errors occur.*

  • if (!sd.begin(chipSelect, SPI_FULL_SPEED)) sd.initErrorHalt();*

  • cout << pstr(“Type is FAT”) << int(sd.vol()->fatType()) << endl;*
    _ cout << pstr("Card size: ") << sd.card()->cardSize()*512E-9;_

  • cout << pstr(" GB (GB = 1E9 bytes)") << endl;*

  • cidDmp();*

  • // open or create file - truncate existing file.*

  • if (!file.open(“BENCH.DAT”, O_CREAT | O_TRUNC | O_RDWR)) {*

  • error(“open failed”);*

  • }*

  • // fill buf with known data*

  • for (uint16_t i = 0; i < (BUF_SIZE-2); i++) {*
    _ buf = ‘A’ + (i % 26);_
    * }*
    * buf[BUF_SIZE-2] = ‘\r’;
    buf[BUF_SIZE-1] = ‘\n’;
    cout << pstr(“File size “) << FILE_SIZE_MB << pstr(” MB\n”);
    cout << pstr(“Buffer size “) << BUF_SIZE << pstr(” bytes\n”);
    _
    cout << pstr(“Starting write test, please wait.”) << endl << endl;_
    _
    // do write test*_
    * uint32_t n = FILE_SIZE/sizeof(buf);
    _
    cout <<pstr(“write speed and latency”) << endl;_
    _
    cout << pstr(“speed,max,min,avg”) << endl;_
    _
    cout << pstr(“KB/Sec,usec,usec,usec”) << endl;_
    for (uint8_t nTest = 0; nTest < WRITE_COUNT; nTest++) {
    _
    file.truncate(0);_
    _
    maxLatency = 0;_
    _
    minLatency = 9999999;_
    _
    totalLatency = 0;_
    _
    t = millis();_
    for (uint32_t i = 0; i < n; i++) {
    uint32_t m = micros();
    _
    if (file.write(buf, sizeof(buf)) != sizeof(buf)) {_
    _
    error(“write failed”);_
    _
    }_
    _
    m = micros() - m;_
    _
    if (maxLatency < m) maxLatency = m;_
    _
    if (minLatency > m) minLatency = m;_
    _
    totalLatency += m;_
    _
    }_
    _
    file.sync();_
    _
    t = millis() - t;_
    _
    s = file.fileSize();_
    _
    cout << s/t <<’,’ << maxLatency << ‘,’ << minLatency;_
    _
    cout << ‘,’ << totalLatency/n << endl;_
    _
    }_
    _
    cout << endl << pstr(“Starting read test, please wait.”) << endl;_
    _
    cout << endl <<pstr(“read speed and latency”) << endl;_
    _
    cout << pstr(“speed,max,min,avg”) << endl;_
    _
    cout << pstr(“KB/Sec,usec,usec,usec”) << endl;_
    _
    // do read test*_
    * for (uint8_t nTest = 0; nTest < READ_COUNT; nTest++) {
    _
    file.rewind();_
    _
    maxLatency = 0;_
    _
    minLatency = 9999999;_
    _
    totalLatency = 0;_
    _
    t = millis();_
    for (uint32_t i = 0; i < n; i++) {
    buf[BUF_SIZE-1] = 0;
    uint32_t m = micros();
    _
    if (file.read(buf, sizeof(buf)) != sizeof(buf)) {_
    _
    error(“read failed”);_
    _
    }_
    _
    m = micros() - m;_
    _
    if (maxLatency < m) maxLatency = m;_
    _
    if (minLatency > m) minLatency = m;_
    _
    totalLatency += m;_
    if (buf[BUF_SIZE-1] != ‘\n’) {
    _
    error(“data check”);_
    _
    }_
    _
    }_
    _
    t = millis() - t;_
    _
    cout << s/t <<’,’ << maxLatency << ‘,’ << minLatency;_
    _
    cout << ‘,’ << totalLatency/n << endl;_
    _
    }_
    _
    cout << endl << pstr(“Done”) << endl;_
    _
    file.close();_
    _
    }_
    ************************************************************************

    I get errors:
    * This report would have more information with*
    * “Show verbose output during compilation”*
    * enabled in File > Preferences.*
    Arduino: 1.0.6 (Linux), Board: “Arduino Mega 2560 or Mega ADK”
    bench:30: error: ‘SdFat’ does not name a type
    bench:33: error: ‘SdFile’ does not name a type
    bench:36: error: ‘ArduinoOutStream’ does not name a type
    bench.ino: In function ‘void cidDmp()’:
    bench:42: error: ‘cid_t’ was not declared in this scope
    bench:42: error: expected `;’ before ‘cid’
    bench:43: error: ‘sd’ was not declared in this scope
    bench:43: error: ‘cid’ was not declared in this scope
    bench:46: error: ‘cout’ was not declared in this scope
    bench:46: error: ‘pstr’ was not declared in this scope
    bench:47: error: ‘hex’ was not declared in this scope
    bench:47: error: ‘cid’ was not declared in this scope
    bench:47: error: ‘dec’ was not declared in this scope
    bench:47: error: ‘endl’ was not declared in this scope
    bench.ino: In function ‘void setup()’:
    bench:65: error: ‘cout’ was not declared in this scope
    bench:65: error: ‘pstr’ was not declared in this scope
    bench:68: error: ‘uppercase’ was not declared in this scope
    bench:68: error: ‘showbase’ was not declared in this scope
    bench:68: error: ‘endl’ was not declared in this scope
    bench.ino: In function ‘void loop()’:
    bench:82: error: ‘cout’ was not declared in this scope
    bench:82: error: ‘pstr’ was not declared in this scope
    bench:86: error: ‘FreeRam’ was not declared in this scope
    bench:86: error: ‘endl’ was not declared in this scope
    bench:90: error: ‘sd’ was not declared in this scope
    bench:90: error: ‘SPI_FULL_SPEED’ was not declared in this scope
    bench:92: error: ‘sd’ was not declared in this scope
    bench:99: error: ‘file’ was not declared in this scope
    bench:99: error: ‘O_CREAT’ was not declared in this scope
    bench:99: error: ‘O_TRUNC’ was not declared in this scope
    bench:99: error: ‘O_RDWR’ was not declared in this scope
    bench:120: error: ‘file’ was not declared in this scope
    bench:148: error: ‘file’ was not declared in this scope
    bench:172: error: ‘file’ was not declared in this scope
    Thank you in advance for your help,
    Murrah Boswell

The library is not installed in the correct place. You must manually install the SdFat folder in your libraries folder.

See the Manual installation section here.

I installed the SdFat library automatically using the 1.0.6 IDE and it got installed in my .../sketchbook/libraries directory. Then, at your suggestion, I removed it from my sketchbook/libraries folder and reinstalled it manually in my ../arduino-1.0.6/ibraries directory and got these errors trying to compile bench:

This report would have more information with "Show verbose output during compilation" enabled in File > Preferences. Arduino: 1.0.6 (Linux), Board: "Arduino Mega 2560 or Mega ADK" bench:30: error: ‘SdFat’ does not name a type bench:33: error: ‘SdFile’ does not name a type bench:36: error: ‘ArduinoOutStream’ does not name a type bench.ino: In function ‘void cidDmp()’: bench:42: error: ‘cid_t’ was not declared in this scope bench:42: error: expected `;' before ‘cid’ bench:43: error: ‘sd’ was not declared in this scope bench:43: error: ‘cid’ was not declared in this scope bench:46: error: ‘cout’ was not declared in this scope bench:46: error: ‘pstr’ was not declared in this scope bench:47: error: ‘hex’ was not declared in this scope bench:47: error: ‘cid’ was not declared in this scope bench:47: error: ‘dec’ was not declared in this scope bench:47: error: ‘endl’ was not declared in this scope bench.ino: In function ‘void setup()’: bench:65: error: ‘cout’ was not declared in this scope bench:65: error: ‘pstr’ was not declared in this scope bench:68: error: ‘uppercase’ was not declared in this scope bench:68: error: ‘showbase’ was not declared in this scope bench:68: error: ‘endl’ was not declared in this scope bench.ino: In function ‘void loop()’: bench:82: error: ‘cout’ was not declared in this scope bench:82: error: ‘pstr’ was not declared in this scope bench:86: error: ‘FreeRam’ was not declared in this scope bench:86: error: ‘endl’ was not declared in this scope bench:90: error: ‘sd’ was not declared in this scope bench:90: error: ‘SPI_FULL_SPEED’ was not declared in this scope bench:92: error: ‘sd’ was not declared in this scope bench:99: error: ‘file’ was not declared in this scope bench:99: error: ‘O_CREAT’ was not declared in this scope bench:99: error: ‘O_TRUNC’ was not declared in this scope bench:99: error: ‘O_RDWR’ was not declared in this scope bench:120: error: ‘file’ was not declared in this scope bench:148: error: ‘file’ was not declared in this scope bench:172: error: ‘file’ was not declared in this scope

Please read this Arduino page again and follow it! I said manual installation.

You must place the SdFat folder, in the sketchbook libraries folder. the path to SdFat.h must be

/home/otrcomm/sketchbook/libraries/SdFat/SdFat.h

Hello fat16lib,

Thank you for your patience. Now I understand. I did copy the SdFat directory with SdFat.h into my sketchbook/libraries and as you said, that was the solution. I can now link to the SdFat libraries.

Thank you very much, Murrah Boswell

hello,

have same error....

I try to use this project.

The arduino 1.5.8 install path on my windows 8 x64 is: E:\Downloads\Arduino\arduino1.5.8_homeduino The path to SdFat.h library is C:\Users\Packy\Documents\Arduino\libraries\SdFat\SdFat.h

gives:

FunkcontroloverNet.ino:13:19: fatal error: SdFat.h: No such file or directory compilation terminated.

So i moved the SdFat.h library to E:\Downloads\Arduino\arduino1.5.8_homeduino\sketchbook\libraries\SdFat\SdFat.h

gives:

FunkcontroloverNet.ino:19:1: error: 'Sdvol' does not name a type FunkcontroloverNet.ino: In function 'void setup()': FunkcontroloverNet.ino:63:3: error: 'vol' was not declared in this scope

:'(