Compile errors when porting to Linux or "other" Windows

Hi

Is it me or is it something else?

I have written a program in IDE 1.0.6 on a W7Pro32 but when others try to compile it on Linux or WinXP or W7 64 bit several errors show up even if they use IDE 1.0.6. I thought Arduino code was transparent or am I doing something wrong?

I have detec the found the following issues to be critical:

  • byte OK on W7Pro32 but not on others, char, unsigned char or uint8_t works

  • prog_char/prog_uchar OK on W7Pro32 but not on the others, const char works

  • #include <arduino.h> OK on W7Pro32 but not on the others but #include <Arduino.h> works

I would like my code to be portable without issues. But how can I verify it myself before wasting others’ time especially if they know very little of Arduino?

Mik D

I have written a program

Nice. Where is it?

Are you sure the others are running 1.0.6 and not 1.6.0? It would be easy to confuse the two and from the errors that sounds like what is happening.

Hi

Hmmm, you may have a point there. I have compiled in on 1.0.6. Will check.

Here is a sample code (not the program in question but it does the same)

//#define windows  // Uncomment if not Windows

#ifdef windows
#include <arduino.h>
#else
#include <Arduino.h>
#endif

#include "avr/pgmspace.h"

#ifdef windows
prog_uchar data[] PROGMEM = {1, 2, 3, 4, 5, 6, 7, 8};
#else
const prog_uchar data[] PROGMEM = {1, 2, 3, 4, 5, 6, 7, 8};
#endif
// Alternative const char

void setup()
{
    #ifdef windows
    byte i;
    #else
    char i;
    #endif
    
    Serial.begin(9600);
     
    for (i = 0; i < 8; i++)
        Serial.println(pgm_read_byte(&data[i]));
}

void loop()
{
}

Mik D

If you use good normal code, everything is okay and fully portable. If you try to confuse the Arduino IDE, you might perhaps find differences (but I doubt it, differences are probably due to older versions).

Use ‘Arduino.h’ with capital ‘A’. But only if you are writing a library. Do not use it in a sketch.
Don’t include “avr/pgmspace.h”, almost everything is already included.
The “prog_uchar” is no longer used. Forget it.
Using ‘byte’ is valid. Unless the Arduino IDE is a bad mix between half-old and half-overwritten new versions with system-wide Arduino IDE version and a unzipped version in home folder together going all wrong.

This is a normal sketch:

// Arduino sketch for Arduino IDE 1.6.0

const byte data[] PROGMEM = {1, 2, 3, 4, 5, 6, 7, 8};

void setup()
{
  byte i;

  Serial.begin(9600);
     
  for (i = 0; i < 8; i++)
    Serial.println(pgm_read_byte(&data[i]));
}

void loop()
{
}

I’m using Arduino in linux and Windows and never had any trouble with portability. No matter how much custom libraries I use or my own board definitions. I try to avoid unnecessary Java things, and I use the newest Arduino IDE.

Hi

Upgraded to 1.6.0 now. But fighting "fatal error: SPI.h: No such file or directory" on two PCs. Have uninstalled all previous Arduino IDE and directories though.

Will be back when I have figured out why this error shows up.

Mik D

PS: Font issues too in 1.6.0.

MikD: But fighting "fatal error: SPI.h: No such file or directory" on two PCs. Have uninstalled all previous Arduino IDE and directories though.

Not in the code you posted.

Windows filenames are not case sensitive but filenames on every other current os are case sensitive.

Mark

True, no SPI error in the sample code. But in the real program on 1.6.0 but not on 1.0.6 both fresh installs. I will be back either with a more comprehensive sample code or when I have found out why.

Yes, I found out about Arduino.h vs arduino.h. Perhaps an idea to warn about "portable issues" in the compiler messages.

Mik D

Hmmm, I have a main file that uses one matching set of x.cpp and x.h files that communicated with a SPI device and #include <SPI.h> is included in the relevant .h file. However, I also have other sets y.cpp + y.h and z.cpp +z.h files where the user is to (un)comment the (ir)relevant declaration depending on what device is used e.g.

/*
#include <SPI.h>
#include “x.h”
x_device device();
*/

#include <SPI.h>
#include “y.h”
y_device device();

/*
#include <Wire.h>
#include “z.h”
z_device device();
*/

It is interesting that #include <SPI.h> MUST be present in the main file even if both x and y are commented out in the above sample concept but #include <Wire.h> does not - in v. 1.6.0. But in 1.0.6 neither #include <SPI.h> nor #include <Wire.h> are needed.

How come?

Mik D

PS: Fixed the font issue. The anti aliasing = true was the culprit.

Because the #include parser in the IDE has been improved. You are supposed to
#include every library used (directly or indirectly) in your top-level sketch file (.ino)
so the build system knows which files to copy to the temporary build directory.

Thanks