📜 ⬆️ ⬇️

Arduino IDE: why sketches are not compiled (and how to avoid it)

image

Since I am intensively developing in the Arduino IDE, I was genuinely worried about this question. Why does a sketch written in one version of the development environment refuse to be compiled in neighboring versions? The same question filled me up with users of the Arduino Mega Server . Why does AMC compile in 1.6.5 and refuse to compile in 1.6.4, 1.6.7 and 1.6.8?

And recently, in the process of porting the Arduino Mega Server to the new Genuino 101 controller, I managed to solve this great mystery. And in this article I will share with you this sacred knowledge and your sketches after that will always be successfully compiled. So…

Logic of things


Logically, code that compiles successfully in any version of the development environment, for example, 1.6.5, must be compiled in neighboring versions of IDE, because these versions differ only in the third character and are almost the same, with minor modifications . But this is not happening. Why?
')

Internal kitchen


To understand this, you need to understand how the versions of the Arduino IDE development environments are formed and how users work with these development environments.

Let's start with the users. Most of them compile primitive projects, figuratively speaking, in 20 lines and with these projects no problems arise. These projects are successfully compiled in any version of the IDE because they use only standard library function calls and do not modify the libraries themselves.

But a somewhat developed project on Arduino no longer fits into “20 lines” and inevitably uses less common functions from libraries (which are more susceptible to modifications from version to version) and inevitably come to the need to modify the libraries themselves to fit their specific project needs.

And once having modified the system library, you become its hostage and are forced to “drag” it from yourself from version to version.

Now let's look at how the Arduino IDE versions are formed. And they are formed arbitrarily (I suspect that ultimately one particular programmer, some Mario) of the issuing team. And what version of a particular library will be included in the distribution and in what form (with what modifications) remains on the conscience of this “Mario”.

And now attention, this is very important! The issuing team pursues only one goal - that the distribution of one version be mutually consistent and consistent within itself. Their task is to ensure that all standard examples work correctly. And it's all! The task of compatibility between versions is not at all set.

And since 99% of users compile projects into “20 lines”, this approach perfectly “rolls” into practice. And the fact that any serious projects are not compiled, these are the problems of these projects. Thank God, now the mechanism of occurrence of the problem is clear and now it has become clear how to deal with it.

Specific example


image

Recall the AMC porting to Genuino 101 (running from version 1.6.7 and higher). Here, the Arduino team saved up another joke for us (well done guys, don't let us relax).

Attempting to compile a project for a new controller resulted in a lot of compiler errors. Analysis of the messages showed that the compiler categorically does not like our Ethernet library. What she did not please the compiler?

We start to understand.

Our library: version = 1.0.4 (the compiler doesn’t like it)
Library from IDE 1.6.7: version = 1.0.4 (the compiler likes it)

But.

Our library: 31 files (the compiler doesn’t like it)
Library from IDE 1.6.7: 31 files (like the compiler)

But.

Our library: 123 KB (the compiler doesn’t like it)
Library from IDE 1.6.7: 123 KB (like the compiler)

But.

In other words, Mario “shoved” an IDE 1.6.7 Ethernet library with the same version number as in IDE 1.6.5, the same number of files and the same size, but with DIFFERENT CONTENT and forgot warn us about this. And this is the most "different content" as the spider holds its paws on the IDE and other lower level libraries (also modified in 1.6.7).

Bravo, Mario! With this approach, nothing will be compiled, except for standard examples and sketches in 20 lines.

A practical solution (puzzles from Arduino)


Now the mechanism of why projects are not compiled in different versions of the Arduino IDE has become crystal clear and, accordingly, the way to solve this problem has also become crystal clear. In this particular case, the solution consists of three parts.


The same must be done with all non-compiled project libraries (that is, find a working version of the library from the IDE and transfer it to its place in the project and modify it, if necessary). But in this case we were lucky, all the other libraries earned normal (because Mario did not have time to modify them quietly, although he could and certainly will do it in new versions of IDE, but we already know how to deal with this).

Conclusion


That's the whole secret of successful work in the Arduino IDE with complex projects. Now you can feel fully armed and it’s easy for you to make your project work in any version of the Arduino IDE.

Source: https://habr.com/ru/post/392931/


All Articles