Precompiler options in Arduino library

Hi experts!

I've been developing a library for Arduino and now I'd like to add some precompiler options with the use of #ifdef's. I'm not sure about how Arduino links libraries with sketch but I'm learning that #defines placed in the sketch are not taken into account by the library:

In mysketch.pde:

#define precomp1
#include "mylibrary.h"

In mylibrary.cpp:

#ifdef precomp1
//Code block 1

In the above example, "Code block 1" is not taken into account so I guess that mylibrary is compiled before evaluating mysketch.pde. In order to make the above precompiler options work I always have to place "#define precomp1" in mylibrary.cpp but this forces me to edit the library source code each time I want a special compilation.

Is there any way to do what I intend?

Thanks in advance.

Libraries and sketches are not meant to share #define names/values. There must be a better way to share information. If you describe what conditional stuff you are trying to make the sketch control in the library, we can off ideas about how to do what you want without the need for #define.

Thanks Paul,

Well, I'd like some parts of the library to be compiled/linked and others not depending on the type of device. For instance, for small low-power sensors, we don't need the serial interface whilst a PC gateway won't need the power managing stuff. I would typically solve this by placing some precompiler conditions into the library code but I understand that this is not possible with Arduino. Anyway, I also understand that I have to de-compose the original code and generate multiple functions for similar purposes, some of them for the low-power sensors and the rest for the usb-based PC gateway. Otherwise, I'm open to any suggestions.

Thanks again!

estratos: Otherwise, I'm open to any suggestions.

Ask hugo75 for a copy of his modified IDE...

...bearing in mind that you may not be able to get an upgrade.