Why does a conditional assembly directive cause the linker to lose library references and fail in the linking stage?
The following code results in ‘digitalWrite’ was not declared in this scope. BUT - change the #if 0 to #if 1, and this links correctly. This was part of a much larger conditional assembly, but I brought this down to the fewest lines to show the issue.
If you make the first line of the file a comment, the problem goes away. I think it’s a bug in the Wiring pre-processor that allows Arduino-style code that doesn’t use function prototypes.
@rickkas7 Perhaps that is true in the particular example that I posted, but in the real app in which this is happening, the first line has the name of the app in a // comment and the link fails.
In the example I posted, if you insert #include "application.h"
a link error will not occur.
But, I inserted that #include in the larger app that is failing, and it did not fix the link error in that version of the code.
For the moment, I removed the conditional assembly directive in my app and commented out the code instead.
@scruff Yes I agree that it is certainly a bug in the pre-processor. Given that fact and the results that this bug could cause (and to avoid someone wasting a lot of time tracking this down), it would not be a bad idea if the documentation noted that when using conditional assembly, the pragma and include statements should be included.
BTW - A blank line at the start of the program did not fix this problem either when I inserted it into the larger app showing the issue. But the pragma and include does resolve the link error.
The problem is not limited to nor does it happen in all cases of conditional compile directives.
It can happen in a lot of not yet fully understood circumstances and hence it’s a bit difficult to document a bug - once it’s completely understood it’ll rather be squashed