Arduino error arduino first defined here, how to fix it?

Hi,

I am facing the error arduino first defined here while trying to compile my code,
I think that the reason is that my class needs to have access to some variables
that are defined in the header of my main skecht.ino. Simplifying I have something like
this

main .ino

#include "myLibt.h"

setup(){
//setup something
}
loop(){
//loop something
}

myLibs.h looks like

#include <Arduino.h>

int x;
int y;
int z;

then I have my class that needs to access x, y and z from myLibs.h, if I do as below, including
myLibs.h in the class, while compiling I get the error mentioned (arduino first defined here)
for each of the variables of myLibs.h that I use. (Notice that the operations of my class
are just examples)

#incldue "myLibs.h"
class A{

int a;
int b;

void m1();
  void m2(){

    x = a + x;
    z = b * z;
  }
}

Why do I have that error and how I can fix it?

Thanks in advance,

Regards

Have you deliberately created your own main.ino program to replace the hidden one that the IDE normally uses ?

arduino first defined here

Where is "here" ?

Please test your example code, fix all the errors, do a Tools > Auto Format, and then repost it in a reply here.

Also posted at:

UKHeliBob:
Have you deliberately created your own main.ino program to replace the hidden one that the IDE normally uses ?
Where is "here" ?

No I haven't done that, the "here" comes from this error

C:\Users\j\AppData\Local\Temp\arduino_build_416253\sketch\qPayload.ino.cpp.o:(.data.gPercentage+0x0): multiple definition of gPercentage'* *C:\Users\j\AppData\Local\Temp\arduino_build_416253\sketch\aPayload.cpp.o:(.data.gPercentage+0x0): first defined here* *C:\Users\j\AppData\Local\Temp\arduino_build_416253\sketch\qPayload.ino.cpp.o: In function loop':

It complains of gPercentage which is defined on qPayload.h tha is included in the main qPayload.ino
but I use that variable as well in aPayload.cpp file

pert:
Please test your example code, fix all the errors, do a Tools > Auto Format, and then repost it in a reply here.

Hi,

#incldue "myLibs.h"
class A{

int a;
int b;

void m1();
  void m2(){

    x = a + x;
    z = b * z;
  }
}

Ummm #incldue "myLibs.h"

include might be better

Tom... :slight_smile: