Creating a library

Right now I am somewhat stuck with the seemingly trivial task of creating a library. My .h is

#ifndef EEPromWearLeveling_h
#define EEPromWearLeveling_h

#include <Arduino.h>

uint8_t get_next_count(const uint8_t count_limit);

#endif

The .cpp file is

#include <EEPromWearLeveling.h>
#include <../EEPROM/EEPROM.h>

extern EEPROMClass EEPROM;

uint8_t get_next_count(const uint8_t count_limit) {
	// n cells to use --> 1/n wear per cll --> n times the life time
	const uint16_t cells_to_use = 512;

	// default cell to change
	uint8_t change_this_cell  = 0;
	// value of the default cell
	uint8_t change_value = EEPROM.read(change_this_cell);

	// will be used to aggregate the count_limit
	// must be able to hold values up to cells_to_use*255 + 1
	uint32_t count = change_value;

	for (uint16_t cell = 1; cell < cells_to_use; ++cell) {
		uint8_t value = EEPROM.read(cell);

		// determine current count by cummulating all cells
		count += value;

		if (value != change_value ) {
			// at the same time find at least one cell that differs
			change_this_cell = cell;
		}
	}

	// Either a cell differs from cell 0 --> change it
	// Otherwise no cell differs from cell 0 --> change cell 0

	// Since a cell might initially hold a value of -1 the % operator must be applied twice
	EEPROM.write(change_this_cell, (EEPROM.read(change_this_cell) % count_limit + 1) % count_limit);

	// return the new count
	return (count + 1) % count_limit;
}

Both reside in the arduino-1.0/libraries/EEPromWearLeveling folder.

The sketch that fails to compile is

#include <EEPromWearLeveling.h>

void setup() {
	uint8_t count = get_next_count(20);

	for (uint8_t pin = 0; pin < 20; ++pin) {
		pinMode(pin, OUTPUT);
		digitalWrite(pin, pin == count);
	}
}

void loop() { }

The compiler always complains like this

...
/Blinkenlight_503_count_resets_with_library.cpp.o /tmp/build3254984387109484155.tmp/EEPromWearLeveling/EEPromWearLeveling.cpp.o /tmp/build3254984387109484155.tmp/core.a -L/tmp/build3254984387109484155.tmp -lm 
EEPromWearLeveling/EEPromWearLeveling.cpp.o: In function `get_next_count(unsigned char)':
/home/udo/Desktop/arduino-1.0/libraries/EEPromWearLeveling/EEPromWearLeveling.cpp:32: undefined reference to `EEPROM'
/home/udo/Desktop/arduino-1.0/libraries/EEPromWearLeveling/EEPromWearLeveling.cpp:32: undefined reference to `EEPROM'
/home/udo/Desktop/arduino-1.0/libraries/EEPromWearLeveling/EEPromWearLeveling.cpp:32: undefined reference to `EEPROMClass::read(int)'
/home/udo/Desktop/arduino-1.0/libraries/EEPromWearLeveling/EEPromWearLeveling.cpp:39: undefined reference to `EEPROM'
/home/udo/Desktop/arduino-1.0/libraries/EEPromWearLeveling/EEPromWearLeveling.cpp:39: undefined reference to `EEPROM'
/home/udo/Desktop/arduino-1.0/libraries/EEPromWearLeveling/EEPromWearLeveling.cpp:39: undefined reference to `EEPROMClass::read(int)'
/home/udo/Desktop/arduino-1.0/libraries/EEPromWearLeveling/EEPromWearLeveling.cpp:54: undefined reference to `EEPROM'
/home/udo/Desktop/arduino-1.0/libraries/EEPromWearLeveling/EEPromWearLeveling.cpp:54: undefined reference to `EEPROM'
/home/udo/Desktop/arduino-1.0/libraries/EEPromWearLeveling/EEPromWearLeveling.cpp:54: undefined reference to `EEPROMClass::read(int)'
/home/udo/Desktop/arduino-1.0/libraries/EEPromWearLeveling/EEPromWearLeveling.cpp:54: undefined reference to `EEPROM'
/home/udo/Desktop/arduino-1.0/libraries/EEPromWearLeveling/EEPromWearLeveling.cpp:54: undefined reference to `EEPROM'
/home/udo/Desktop/arduino-1.0/libraries/EEPromWearLeveling/EEPromWearLeveling.cpp:54: undefined reference to `EEPROMClass::write(int, unsigned char)'

Would someone please hit me with a clue bat?

Try adding #include <EEPROM.h> in your .pde (or .ino) file. I suspect the arduino preprocessor isn't linking in the EEPROM.cpp file.

You nailed it. Thanks a lot. Any ideas how I can convince this stupid IDE to pick up its own libraries the way it should?

Here's the issue regarding it:
http://code.google.com/p/arduino/issues/detail?id=236

OK, thanks for the examplanation. To summarize it in my terms: the build + link process is broken, the IDE sucks. I should stick to make or scons unless I am writing tutorials :frowning: