// This construct doesn't work. Wire.h will be included no matter what.
// So 1244 bytes are always added unless the #include is commented out.
#define ADD_WIRE false
#if (ADD_WIRE)
#include <Wire.h> // <<< can only comment out to not include
#endif
void setup(){
}
void loop(){
}
I was surprised to find that Wire.h is always included regardless of the setting of the #define.
If it's not the right way to do this, is there a way that works?
Are all the references to the wire library #ifdef'd out? The IDE might be smart enough to add in Wire.h if it sees any reference to the Wire library. Also, try a #undefine right before your #ifdef.
What we need is a clean button.
Try a new test script that has never had wire.h defined.
/*
* BOF preprocessor bug prevent
* insert me on top of your arduino-code
*/
#define nop() __asm volatile ("nop")
#if 1
nop();
#endif
/*
* EOF preprocessor bug prevent
*/
before the sketch I first posted with the same results - 1710 bytes and 466 bytes if the #include is commented out.
Unless I missed something in that example, that should be the workaround.
It appears that the precompiler makes one pass and seems to handle #includes before #defines.
It appears that the precompiler makes one pass and seems to handle #includes before #defines.
Are you looking at the .ino file or the .cpp file that the IDE constructs from the .ino file? The IDE does some "unusual" things to convert a .ino file to a .cpp file.
Not exactly.
I'm trying to save the 1244 bytes that Wire.h adds to the sketch even when it's not defined.
The fact that it's not "compiled in enough" to satisfy Wire.begin is interesting, buy if you try the sketch as I have it in the first post,
compile it and note record the sketch size,
and then comment out the #include and note the sketch size again, you will see a 1244 byte difference.
I'm using this construct in another sketch that is close to the wall, and I'd like to avoid this overhead by setting a #define.
That's what I'm trying to achieve but it's looking unlikely.
The code I posted did not compile in Wire.h at all. However, I think what you're complaining about is actually the linker. For reasons which seem bizarre to me, the Arduino approach is to copy the sketch file and all associated code tabs, plus all the libraries and bits of the Arduino runtime framework which it references, into a temporary directory - and then compile and link everything. What's happening here is that the Arduino IDE is noticing the #include <wire.h> in your sketch, decided you are using the associated library, and including that library in the build. In theory the linker is smart enough to only link in the library functions that your code actually refers to, but in practice it seems to be pulling in quite a lot of junk in your case.
As far as I can see, the only options you have to avoid that are to comment out the #include to stop the IDE screwing up, or move to a grown up IDE.
Peter, that seems to describe what is happening. For me, the question is answered and I guess I'll have to just comment out that #include in addition to setting the #define false. Thanks for everyone's help.