Alter library compilation with preprocessor directives in the sketch

Hey there!
I'm wrote a complete library for Gamebuino, a handheld console based on Arduino I released on Indiegogo 3 days ago (check out the trailer on Gamebuino: an Arduino handheld console | Indiegogo). The library includes a lot of things, like a fancy GUI or 4 channel sound generation. That's really handy, but the problem is that it takes a lot of ROM & RAM. I would like to be able to add some preprocessor directives at the beginning of my sketches to disable some parts of the library depending on what I need , like #define NOSOUND 1 to disable the whole sound generation.
Is that possible ? If I use #ifdef NOSOUND in the library and #define NOSOUND 1 in my sketch, it won't work because the sketch comes after the library :cry:
I can't put the different parts of the library in different libraries, because they all depend from each other, and that would be really messy.
I didn't find any neat solution, I hope you will! :slight_smile:

It cannot be done.

The library and the sketch are different "compilation units". That is, each is a completely separate piece of code, and one cannot affect the compilation of another.

The only way to do it is to share a single "config" file between both the sketch and the library. You could use "config.h" which you then include in both, and your #defines go in there instead.

Thank you for your quick answer!

Actually I already have a "settings.h", but you need to edit it every time depending on what you need in the program/game you are currently compiling... For example, I could only use 1 channel for the sound in a game which require a lot of RAM, and 4 channels in another game. Not really handy :frowning: