-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Compilation error: conditional #include inside #if #4512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Could you try the hourly build (from the downloads section on arduino.cc)? I believe that this issue might have been fixed in git recently. |
just checked with hourly build (2 February 2016 10:15:23 GMT) - same results:
|
Ah, now I looked more closely at your example and indeed, this is not expected to work. The problem is that both .cpp files are compiled, regardless of whether the corresponding .h file is included. Arduino or the compiler has no way to match .h files with .cpp files, so all .cpp files in a sketch are always compiled. There is currently no way to specify what files to (not) compile. I can see ways around this:
Since this isn't so much a bug in the IDE, as well as a mismatch in your expectations (and because it won't be easy to change the IDE to meet your expectations in a reliable way), I'll go ahead and close this issue. Feel free to leave more comments if you have questions, though, or if you think there is something the IDE should change. |
It might not be far-fetched or difficult to add support for arch specific code in the IDE in a manner similar to what was done in the boards packaging: the IDE could with minimum effort support arch specific folders insde the a sketch's root folder and ensure that the contents only gets compiled when the matching hardware is targetted. Possibly something Arduino Create will support?! |
@e-moe |
The build process is (and will remain) the same for the Java IDE and for Create.
We tried to add support for the |
@mikaelpatel , @matthijskooijman I tried to show minimal example of code to demonstrate errors. Actually I'm trying to fix build errors in https://github.com/digistump/DigistumpArduino/blob/master/digistump-avr/libraries/DigisparkLCD/LiquidCrystal_I2C.cpp:
both of these libraries ( |
@cmaglie thank you for sharing that part of the history of the platform. If I may ask, I found some past entries referencing the possibility of adding support for Makefile based builds in the IDE. From what I could gather, the discussions seemed centered around libraries. Has there been any similar discussions regarding support Makefile for sketches?! As I shared previously, I found that once the console stream machinery was straightened up, it was straightforward to address the 'floating' compiler messages - they follow the active editor - and even simpler to support Makefiles - basically remove most of the code from Compiler.java (I decided to expose a preference, but it is not required). In light of this apparent ease, I was wondering if there was not another deeper reason for not support Makefile. |
@e-moe If I may share: when dealing with multi-environment code, I tend to favor a solution where inside the |
@lmihalkovic , yes. but I can't change any of these libraries ( |
@e-moe, if I understand correctly, the original problem you had with the Wire and TinyWireM libraries selects between two libraries, while your reduced example selects between files in your sketch, making them significantly different. Did you try your original problem with the hourly build? IIUC the code you pasted is from the .cpp file in the library you linked. However, what does the .ino sketch look like? If you're using the example from that library, you might be including TinyWireM.h from the .ino file unconditionally? If not, can you perhaps provide the full sketch and the full errors? |
@matthijskooijman, yep, I tried hourly build on my original problem - same results. Code samples are slightly different but they shares the same idea. Compare my reduced example:
with my original issue:
|
@e-moe, yeah but the primary difference between your example and the real case is that a.cpp and b.cpp are in the sketch? Or did you create two test libraries for them? Did you see if your .ino file perhaps unconditionally includes either library? |
@matthijskooijman, you right - my files was in sketch. they are not separate libs. But I also tried to compile my original issue with Wire and TinyWireM libraries with the same error message. |
@e-moe, okay. But in your original issue with the two libraries, did you have an #include in the .ino file? |
@matthijskooijman , this is my ino file:
|
And this is your problem:
Your .ino file always includes TinyWireM, even when not compiling for ATtiny, which causes the TinyWireM to be included and conflict with the Wire library included by LiquidCrystal_I2c.h. You'll have to apply the same trick from the liquid crystal library here, or perhaps just remove the include altogether (since, I think, Arduino 1.6.6 it is no longer necessary for the .ino file to include all libraries needed, they are also detected if a library includes another library). |
but my .ino is compiles for attiny and I need to use |
@e-moe, I'm assuming this error occurs when you have a non-tiny board selected in the IDE. Or does this also occur when compiling for an attiny board? Perhaps it is one that is not listed in the |
board is selected correctly. moreover I tried to explicitly set |
Please try to be explicit. What is "correctly"? I originally thought your problem was that your sketch did not compile both for ATmega and ATtiny boards, but now I believe your problem might be that the ATtiny build isn't working?
That won't help: The library's .cpp file is compiled separately from the .ino file and does not include the .ino file, so nothing you do in the .ino file will affect the compilation of the .cpp file (though it might cause duplicate definitions in the linker stage after compilation). In particular, any #defines in a .ino file (or .cpp file for that matter) are not visible in another .cpp file. |
sorry for been not specific enough. my board is "Digispark (Default - 16.5mhz)" from https://raw.githubusercontent.com/digistump/arduino-boards-index/master/package_digistump_index.json. it's built on ATtiny85 (see http://digistump.com/wiki/digispark/tutorials/digispark). I'm trying to compile example from https://github.com/digistump/DigistumpArduino/tree/master/digistump-avr/libraries/DigisparkLCD |
Ok, so that should define |
|
Ah, I think I see what's happening:
You're not actually using the LiquidCrystal_I2C library you think you're using, but a separately installed one. I think the only way to fix that is to remove the other libraries from your |
sorry, one more output (removed unexpected libraries in home folder):
|
Ah, so now the error message changed and there is a different problem. And now I do think you've found an actual bug, though it is a problem in arduino-builder, not the Arduino IDE. So, I've opened up a new bug report here: arduino/arduino-builder#106 We'll have to double-check that my deducation is correct, but I think we have enough info to reproduce and fix this now. If there is anything else we need from you, I'll let you know. Thanks for keeping the replies coming :-) |
welcome :) thanks to you too for helping me and your effort with finding actual bug! |
no, there is no deeper reason (though we can still discuss the usefulness of such feature, but this will go offtopic here, maybe we can continue on the specific issue). About the |
Hi guys, I'm trying to implement one class for two different MCU types using conditional #include.
Is there any way to avoid error and specific files compilation (e.g. compile only a.cpp or b.cpp but not both of them)?
Arduino 1.6.7. Mac OS X El Capitan.
sketch:
a.h:
a.cpp
b.h:
b.cpp
The text was updated successfully, but these errors were encountered: